Select your Language

Get sub String from String

 String str = 'a"aaabc"';

system.debug('String between quotes is ' + str.subStringBetween('"', '"'));


Result: String between quotes is aaabc



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

Result:  'Expected is xxyz


Q: How to Join List of string into the string

 emailDisplay = string.join(contemailList, ',');

where emailDisplay  is a string variable


Q check string is Empty

String.isEmpty(refNumber)                           where refNumber is a string variable

Q. Replcae all  special character .

String strText = 'Welcome - to! % $sale&sforce \\ /blog # to%';
strText = strText.replaceAll('[^a-zA-Z0-9\\s+]', '');
System.debug('strText ======> '+strText);

OUTPUT: Welcome to salesforce blog to

Q. Get string index 

string a='Intimation referral -Amrit';
system.debug('a: '+a.lastIndexof('-'));

Ans: a: 20

Quse: Get string after the symbol

string s='INtimation referral-Amrit';
system.debug('s: '+s.substring(s.lastIndexof('-') + 1));

Ans : Amrit


Ques: Get before string and get after string

string s='INtimation referral-  Amrit ';
string a='INtimation referral -Amrit';
system.debug('a: '+a.substringAfter('-'));
system.debug('a: '+a.substringbefore('-'));

Ans: 
Amrit 
'INtimation referral 



No comments:

Post a Comment