How to find substring between characters in Salesforce using apex?

How to find substring between characters in Salesforce using apex?

Sample Code for String between double quotes:

String str = ‘a”abc”‘;
System.debug( ‘String between quotes is ‘ + str.subStringBetween( ‘”‘, ‘”‘ ) );


Output:

 

Sample Code for String between white spaces:
String str = ‘ abcxyz ‘;
System.debug( ‘String between space is ‘ + str.subStringBetween( ‘ ‘, ‘ ‘ ) );
 
Output: 
 

 

Leave a Reply