Contains function in PilotScript

Hi

I was going to send this as a support request, but thought it was a) too trivial, and b) possibly of interest to others.

I was wondering about the behaviour of the contains function in PilotScript. If I have a list of values on my datastream that I want to test against an array, will the contains function only provide the first match it sees then ignore any others?

Example:
@myarray := [7,9,12,15]
myData := 7, 9, 7, 21, 36, 3...

ContainsResult := 7, 9

ie having seen 7 once, it is no longer matched? If so, is there a way to do the match with replacement so that the next occurrence of 7 will also be matched?

Thanks
Hassan
Answers 2
JB
JB 2010-04-14
Hi,
The contains function is a boolean function (PP help), and so it is just anwering the question does it contain or not a particular value. It is not going to look for repetitions.

It is quite useful to avoid loops.

For your problem you may have to loop through your array and count the number of times you find your value.

Cheers,

Jérémy
PD
PD 2010-04-14
Hi,

If you are looking for integer vector comparison, you should take a look at the BitSet functions (BitSetAnd, BitSetOr, etc.).

Convert vector (array) A, to a set with
contract(' ',A);
A := '1 3 5 7';
B := '1 2 1 5 9';
C := BitSetAnd(A,B); -> 1 5
D := BitSetOr(A, B); -> 1 2 3 5 7 9

Though, BitSetAnd would also return non repeated match in your case.You can address this by using a regular expression, see below.

Q := strreplace(A,' ','|');
M := rmatch(B, '('.Q.')','g'); -> 1 1 5
This would with non numerical vectors as well.

Cheers,