0

I am trying to Compare two strings which are delimited by SEMI-COLUMN (;). I have made sure I SPLIT them and the store them in lists. In the below example, I receive an error for BALL for all other strings in TEST 3 pass. I just need to make sure all of the values in TEST3 are available in TEST2.

Any help is appreciated and would be a big learning curve for me.

 STRING TEST1 = 'MY ; BALL ; CAR; PEN';
LIST<STRING> TEST2 = TEST1.SPLIT(';');
SYSTEM.debug(TEST2);

STRING TEST3 = 'MY ; BALL; CAR';
for(string test4:TEST3.split(';')){
    system.debug(test4);
    if(TEST2.contains(test4)){
        system.debug('working');
        system.debug(test2);
    }
    else{
        system.debug('not working');
    }
}

1 Answer 1

0

You've got a trailing space after 'BALL' in Test1, but no trailing space after BALL in Test3.

If you remove the trailing space, it works.

1
  • Thanks for the reply. This is just a test class I am trying to implement for a bigger implementation where Users manually enter into TEST3 and there is TEST1 is a Multi Picklist value. How to eliminate spacing and then compare? Mar 2, 2020 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .