When i tried to run the following code snippet anonymously in dev console i got different boolean results. Is string method startsWith(String) case-sensitive or not?

String s1 = 'Thomas Inc';

It returns false when i changed some letters to upper case. Do i have to convert the source and the comparison string to any of the cases before comparing? Do we have case-insensitive version of this method? Please advice.


The String.startsWith method is case sensitive.

However there is a String.startsWithIgnoreCase method which as the name notes is case insensitive.

  • Hmmmm didn't realize this. I googled salesforce string methods. Came to the page and it has a lot less... salesforce.com/us/developer/docs/dbcom_apex250/Content/…
    – dphil
    Jul 30 '14 at 2:29
  • @dphil those are the docs for database.com's release, which was APIv25. I don't know why that's the top result for apex docs but it's a pretty old copy of them at this point. Jul 30 '14 at 5:02

Your best bet is doing something like:

String s1 = 'Thomas Inc';

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.