aspose file tools*
The moose likes Beginning Java and the fly likes string search & replace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string search & replace" Watch "string search & replace" New topic
Author

string search & replace

Chitra Jay
Ranch Hand

Joined: May 02, 2002
Posts: 76
Hi,
Pls help me with this issue.
Contents of the text file:
bla bla bla %s
bla bla bla bla

...more contents here...
%i bla bla %s
--end of text file.

I would like to replace the %s,%i,%s with 3 values i pass in the arguments.
eg. if send 1,2,3 then contents of the text file should have %s replaced with 1, %i replaced with 2 and %s replaced with 3. (in the order they appear in the file). I dont need to bother with whether its %s or %i, but only i need to replace %s or %i with the parameters i pass. I can read the contents of the file into a string. but how to replace values in the order specified.
Fintan Quill
Greenhorn

Joined: Feb 28, 2006
Posts: 8
Perhaps you could use a Collection class with key/value pairs where %s is a key and 1 is its value, or possibly vice-versa. I could be misinterpreting your dilemma however!
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
You could call the String.replaceFirst() method three different times with the same regex and different repacement Strings


[ April 20, 2006: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"CJ,"

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name -- like Chitra Jay, for example.

You can edit your name here.

Thank you for your prompt attention!

-Marc


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string search & replace