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!
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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 '-'....
raabhim (March 23rd, 2012)
Last edited by raabhim; March 23rd, 2012 at 01:42 PM.
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
Last edited by KucerakJM; March 23rd, 2012 at 02:09 PM.
raabhim (March 23rd, 2012)
just what I needed.
Thank you very much!