I have
String a = "data=\"0\"1\"1\"1\"1\"0\"0\"0\"0\"0\"0\"1\"1\"1\"1\"0\"0\"0\"0\"0\"1\"1\"1\"1\"1\\\\";
How can i replace
"to\"- and
\to\\
?
String result = a.replace("\"", "\\\"");
OR
String result = a.replace(""", "\"");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This would first replace all
\with\\and then all"with\"if that is what you want.Note that doing it the other way round would result in
"being replaced with\\"in the end, since first it get replaced with\"and then the\would be replaced with\\resulting in\\".Additional note: your data string is not well-formed and should not compile: it ends in
\"which is not a valid string literal delimiter (the literal ends in\\\\\"which would be the string data\\") – change that to an even number of slashes or add another"to the end in order to fix that.