February 3, 2015

How to find substring of string after particular character using Apex in Salesforce?

substringAfter() is used to find substring of string after particular character using Apex in Salesforce

Sample Code:

String str = 'abc-xyz';
system.debug('Expected is ' + str.substringAfter('-'));

Output:


4 comments:

  1. How about finding multiple substrings in a string ?

    Ex: String str = 'abc-xyz-123';

    ReplyDelete
    Replies
    1. Use split method.
      Example - https://www.infallibletechie.com/2020/03/string-split-method-in-apex-in.html

      Delete
  2. how we can use this function in report builder

    ReplyDelete
    Replies
    1. Report builder doesn't support this.
      The example is for using Apex.

      Delete