function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael MMichael M 

Insert character into string

This may be a basic question, but I need to manipulate a string. I have a string that is a phone number in this format: +18888888888. I need it to become 888-888-8888. How can I do so?
Thank you!
Best Answer chosen by Michael M
MTBRiderMTBRider
Here's one way:
public static String formatPhoneNumber(String pNum) {
   pNum = pNum.right(10);
   return pNum.left(3) +  '- ' + pNum.substring(3, 6) + '-' + pNum.right(4);		
}

All Answers

MTBRiderMTBRider
Here's one way:
public static String formatPhoneNumber(String pNum) {
   pNum = pNum.right(10);
   return pNum.left(3) +  '- ' + pNum.substring(3, 6) + '-' + pNum.right(4);		
}
This was selected as the best answer
Michael MMichael M
Cool- thank you