Notes
public class StringUtility {
public static Integer StringToInteger(String intString) {
try {
return intString != null ? Integer.valueOf(intString) : 0;
} catch (Exception e) {
return 0;
}
}
public static String formatNamesAsHtmlList(List<String> names) {
String formattedList = '<b><ol style="color:green">';
for (String name : names) {
formattedList += '<li>' + name + '</li>';
}
formattedList += '</ol></b>';
return formattedList;
}
public static List<String> StringToCollection (String CollectionOfEmails){
List<String> EmailList = new List<String>();
if(String.isBlank(CollectionOfEmails)){
return EmailList;
}
for (String email : CollectionOfEmails.split(';')) {
EmailList.add(email.trim());
}
return EmailList;
}
public static String formatPhoneNumber(String phoneNumber) {
if (String.isBlank(phoneNumber) || phoneNumber.length() != 10 || !phoneNumber.isNumeric()) {
throw new IllegalArgumentException('Invalid phone number. Must be a 10-digit numeric string.');
}
String countryCode = '+1';
String formatted = countryCode + ' ' +
phoneNumber.substring(0, 3) + ' ' +
phoneNumber.substring(3, 6) + ' ' +
phoneNumber.substring(6, 8) + ' ' +
phoneNumber.substring(8, 10);
return formatted;
}
}
Video
Video does not exists.