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');
    }
}
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.

| improve this answer | |
  • 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? – vinieth anirudh Mar 2 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.