Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

replace double inverted commas into slash double inverted commas in string

Thread view: 
AviraM - 28 Sep 2006 08:38 GMT
hi all

I have a var of String type
the string include double inverted commas (") and I need to replace it
into slash double inverted commas (\")

example:
original: "abc"de"
result: "abc\"de"

that problem came because I got the string from the databse and I need
the string to  make a query from the databae comparing as is but the
all parse is illegal without change my string

thanks all
Knute Johnson - 28 Sep 2006 17:52 GMT
> hi all
>
[quoted text clipped - 11 lines]
>
> thanks all

If I were better with regex I could probably do this in one step :-).

public class test8 {
    public static void main(String[] args) {
        String str = "\"abc\"def \"13s\"";
        System.out.println(str);
        str = str.replaceAll("\"","\\\\\"");
        System.out.println(str);
        str = str.replaceAll("^\\\\\"(.*)\\\\\"$","\"$1\"");
        System.out.println(str);
    }
}

Signature

Knute Johnson
email s/nospam/knute/

Manish Pandit - 28 Sep 2006 19:19 GMT
Hi,

You could use Apache Commons StringUtils API to escape the strings
you're getting from the database to java-escaped versions.

Here is the link:

http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/StringEscapeU
tils.html#escapeJava(java.lang.String
)

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.