replace double inverted commas into slash double inverted commas in string

A

AviraM

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
 
K

Knute Johnson

AviraM said:
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

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top