Activity Forums Salesforce® Discussions How can we ignore spaces when comparing two values?

  • Ajit

    Member
    August 10, 2016 at 11:55 am

    Hi Pranav,

    If you are comparing string then you can use the string methods to delete white spaces from the string

    String s1 = ' Hello Jane ';
    String s2 = 'HelloJane';
    System.assertEquals(s2, s1.deleteWhitespace());

    it will delete all the white spaces.

     

    tring s1 = ' Hello! ';
    String trimmed = s1.trim();
    system.assertEquals('Hello!', trimmed);

    it will remove trailing and leadin white spaces.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos