Try String s1 = s.replace("\"", "\\\"");
Explanation:
When referencing a quote or backslash in a string, i.e. Anything inside double quotation marks requires \
to indicate that you want the quote to appear in quotation marks rather than ending in quotation marks. Does this make sense?
For example, you should write String message = "She said \"Hello\" the other day."
, so backslashes mean that quotation marks do not actually end the entire string, but rather are part of the string.
source share