File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replace String

 
Edward Durai
Ranch Hand
Posts: 223
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider i have string like

"select [columnName] from tablename"

I want to replace [columnName] to [UserName]

finally, i need "select [UserName] from tablename";

how?
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use regular expression. Take a look at Pattern and Matcher classes.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like the following may do the trick. You'll need to add a loop to deal with the case when findStr can occur more than once in targetStr. (The indices may be off, but you get the idea.)
 
Rahim Vindhani
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isnt it as simple as



if its more than one time, You can use replaceAll (only JDK 1.4 and later I guess)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic