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