Replace ‘ with \’ in a string

You have to escape the “\”:

str.replace("'","\\'")

“\” is an escape sequence indicator, which, to be used as a normal char, has to be escaped (by) itself.

Leave a Comment