Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting the String to Phone format

 
Bhavik Patel
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a String 1234567890 and i want it in 123-456-7890 format.. is there anyway i can use the formatter or any other class to achieve this and convert it to phone number format..

Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd probably write a one line conversion method using substring and concatenation. Or use a generalized string rearranger from my own library. Let's see if somebody chimes in with a way to do it with Formatter.
 
dilip upadhyay
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can use replace method of string class
 
Henry Wong
author
Marshal
Pie
Posts: 21123
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by dilip upadhyay:
u can use replace method of string class


Using the regex engine to do this may be an overkill, but let's see...



Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic