• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replacing a substring from a string

 
gradnash nash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use replaceAll
 
Jherald Lacambra
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
gradnash nash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot for the reply.

I really appreciate it.

I will try.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic