Page 1 of 1

Intersection between two strings

Posted: September 16th, 2016, 2:46 pm
by hamouda1987
Hello good people ,

I have two strings
1 string="lokmij" with maximum 12 caracteres and we can't have two caracters with same values
2 string="l" with maximum 1 caractere.

what i want to do is to comapre this two strings and the result will be a string with caracters not commun between this two strings.
for example between "ABC" and "A" the result will be "BC" .

can i do that ?
kind regards

Re: Intersection between two strings

Posted: September 17th, 2016, 1:29 am
by Saint
Hi,
I assume string2 will always be a part of string1? Else what will be the output? Say string1 ABC and string2 is D.
Otherwise, lets say you want the result in string 3 (with length 11 - can make it 12 if string 2 will not be part of string 1 sometimes), then the following code should work. Remember to declare i and k in proc global..

Cheers...

Code: Select all

PROC STRING3
PREPROC
k = 1;
i = 1;
while i <= 12 do
   if string2[1:1] = string1[i:1] then
     i = i + 1;
   else
    string3[k:1] = string1[i:1];
     i = i + 1;
     k = k + 1;
   endif;
enddo;