Latest Updates
Travel to Technology
String split with multiple special character in apex
Just experienced issue to split the string value, one of API integration where JSON string attribute contains the many special character that I need to split and reorganize the value then store the value in salesforce field.
Example:
JSON Response
{
"To": "Test User <test.user@test.com>",
"Cc": "Test User1 <test.user1@test.com,Test User2 <test.user2@test.com;Test User3 <test.user3@test.com;Test User4 <test.user4@test.com"
}Split the string after you parsed JSON string and stored the value in String variable – you can use regular expression in string split method
String strEmailCC = objREsponse.cc;
list<String> lstEmailString = strEmailCC.split('[;,]');Apex code to remove the name from email Address:
for(String strEmail : lstEmailString) {
if(strEmail.endsWith('>')) {
strEmail = strEmail.substring(strEmail.indexOf('<', 1)+1, strEmail.length()-1);
}
}
Our Recent Blogs
-
27 Jan, 2021
Salesforce Architect Domain Exam
-
23 Nov, 2016
Salesforce Certified Technical Architect New Path
-
28 Mar, 2018
Salesforce Release Exam in Trailhead Certification
-
29 Dec, 2021
Salesforce Certifications