• Post Reply Bookmark Topic Watch Topic
  • New Topic

String function to enclose a word in quotes  RSS feed

 
Sangeetha Verkot
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to search for a particular word that the user enters in a textfield and append either single or double quotes to it.
e.g.
mySearchField = StringUtils.replace(mySearchField, "xyz", "here I want to replace xyz with 'xyz' or "xyz" );
Is there a way to accomplish this? Thanks!
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sangeetha,

You might want to consider using the replace method in the String class. So, something like:

If you want to use single quotes, just put them in there like this:

If you want to use double quotes, use the backslash as the escape character:


Hope this helps,
Jeff
 
Sangeetha Verkot
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked..Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!