Thursday, 5 April 2018

salesforce - Remove all special characters from the given string.


String s1 = '$!(5-14)';
String regExp = '[^a-zA-Z0-9-]';
String replacement = '';
String s2 = s1.replaceAll(regExp, replacement);
System.assertEquals('5-14', s2);
System.debug('s2: '+s2);
String[] parts=s2.split('-');
for(Integer i=0;i<parts.size();i++){
 System.debug('Part-'+(i+1)+'= '+parts[i]);
}


No comments:

Post a Comment