wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Replacing a substring from a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Replacing a substring from a string" Watch "Replacing a substring from a string" New topic
Author

Replacing a substring from a string

gradnash nash
Greenhorn

Joined: Mar 14, 2006
Posts: 11
Hello All,

I would like to replace a particular occurrence of a substring in a string with another substring.

for eg : Given string is : people <tag> help </tag> always

expected string is people <font> help </font> always.

I need to replace the occurrence of <tag> </tag> with <font></font>

help would be appreciated.

Thanks
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can use replaceAll
Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
Originally posted by gradnash nash:
Hello All,

I would like to replace a particular occurrence of a substring in a string with another substring.

for eg : Given string is : people <tag> help </tag> always

expected string is people <font> help </font> always.

I need to replace the occurrence of <tag> </tag> with <font></font>

help would be appreciated.

Thanks


String htmlTags = "people <tag> help </tag>";
htmlTags = htmlTags.replaceAll("tag","font");


jherald
gradnash nash
Greenhorn

Joined: Mar 14, 2006
Posts: 11
thanks a lot for the reply.

I really appreciate it.

I will try.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replacing a substring from a string