Activity Forums Salesforce® Discussions Splitting label values on '\n' is not getting same values on comparing

  • Splitting label values on '\n' is not getting same values on comparing

    Posted by Utsav on April 14, 2016 at 7:30 am

    When i am comparing two same values in label by splitting values on the basis of  '\n'

    It is getting some problem on the last value of the list returned by System.Label.QuoteFCLFix_OriginServices.split('\n')

    How can i solve this issue?

    for(String c: System.Label.QuoteFCL_OriginServices.split('\n')) {
    FCLOriginServices.add(new wrappingServices(c));
    }

    list<wrappingServices> tempWrapList = new list<wrappingServices>();
    for(wrappingServices objWrap : FCLOriginServices){
    for(String c: System.Label.QuoteFCLFix_OriginServices.split('\n')) {
    if(objWrap.label == c ){
    objWrap.selected = true;
    }
    }
    tempWrapList.add(objWrap);
    }
    FCLOriginServices.clear();
    FCLOriginServices.addall(tempWrapList);

    shariq replied 6 years, 1 month ago 5 Members · 7 Replies
  • 7 Replies
  • Rachit

    Member
    April 14, 2016 at 8:16 am

    Hi Utsav

    I think you need to to use equalIgnoreCase method of string class to be more precise.Let me know if this works!

     

  • Utsav

    Member
    April 14, 2016 at 8:20 am

    Hi Rachit

    It works actually, but why it is working i have a doubt there.

    Hope i make sense to you. 🙂

  • Naman

    Member
    April 14, 2016 at 8:34 am

    You must had some Camel case in your string so equalIgnoreCase worked.

  • Utsav

    Member
    April 14, 2016 at 8:44 am

    Hi Naman

    I thought yes it may be due to case of charcters but when read the following conversation which says == is same as equalignorecase and === matches the case then why my code is not working?

    http://salesforce.stackexchange.com/questions/80456/is-there-any-difference-in-equals-and-for-string-variables

  • Naman

    Member
    April 18, 2016 at 11:29 am

    Yes, thats correct but look at the code you are comparing

    if(objWrap.label == c ){
    objWrap.selected = true;
    }

    objWrap.label is not yet bind to the string type so you have to ignore case separately.

  • Parul

    Member
    September 20, 2018 at 12:38 am

    Hi,

    > equals(stringOrId) Returns true if the passed-in object is not null and represents the same binary sequence of characters as the current string. Use this method to compare a string to an object that represents a string or an ID.

    == is same as equalsIgnoreCase(secondString)

    Returns true if the secondString is not null and represents the same sequence of characters as the String that called the method, ignoring case.

  • shariq

    Member
    September 20, 2018 at 7:42 pm

    Hi,

    I think there is a problem regarding string case, try equalIgnoreCase().

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs