string.replace("\"", "\\\"")
You want to replace " with \" . Since both " and \ have a certain meaning, you should avoid them correctly by adding the previous \ before each.
So " → \" and \" → \\\" . And since you want the compiler to understand that it is String, you need to wrap each line with double quotes So " → \" and "\"" → "\\\"" .
Ronk source share