Hi there.
Is there any method in the String class that will take 1234567899 and return - 123-456-7899 ?
Reason: get a user input for phone number and return it as a readable phone number format.
Thanks for you help! :)
Printable View
Hi there.
Is there any method in the String class that will take 1234567899 and return - 123-456-7899 ?
Reason: get a user input for phone number and return it as a readable phone number format.
Thanks for you help! :)
I'm a beginner myself, but I'd probably read the string as a set of char's, and say after 3 char's add '-', after another 3 char's add '-'....
You could always check out String.format();
EDIT:
for example
String s = "TestString";
System.out.println(s.format("%s.%s", s.substring(0, 4), s.substring(4, s.length())));
that would output
Test.String
just what I needed.
Thank you very much!