• Post Reply Bookmark Topic Watch Topic
  • New Topic

String global replacement - pattern  RSS feed

 
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to replace globally like this from 214-123-4567 to 1-800-123-234-456 using pattern/some other java API like String.pattern() ?
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you been through the API documentation for the String class?
Have you considered using a StringBuilder and its insert method?
 
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kri shan wrote:How to replace globally like this from 214-123-4567 to 1-800-123-234-456 using pattern/some other java API like String.pattern() ?

What do you mean by Globally here? As Campbell said, checkout the API doc for String, there are many functions available to replace,
 
Greenhorn
Posts: 29
IntelliJ IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Regular Expressions. Regex Tutorial
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!