Intersection between two strings

Discussions about CSEntry
Post Reply
hamouda1987
Posts: 9
Joined: June 14th, 2016, 7:16 am

Intersection between two strings

Post 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
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: Intersection between two strings

Post 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;
Post Reply