aspose file tools
The moose likes Beginning Java and the fly likes String function to enclose a word in quotes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "String function to enclose a word in quotes" Watch "String function to enclose a word in quotes" New topic
Author

String function to enclose a word in quotes

Sangeetha Verkot
Greenhorn

Joined: Jun 07, 2007
Posts: 4
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

Joined: Apr 07, 2007
Posts: 230
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


Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
Sangeetha Verkot
Greenhorn

Joined: Jun 07, 2007
Posts: 4
It worked..Thanks.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: String function to enclose a word in quotes
 
Similar Threads
objects eligible for GC
why we called a servlet an controller
Extra Path Info weirdness
textbox taking only one word
A stange error while storing single quote in a table