Alex Rivera | Logout

Adding backslashes without escaping

Asked 2010-02-01T19:38:09.843
42

I need to escape a & (ampersand) character in a string. The problem is whenever I string = string.replace ('&', '\&') the result is '\\&'. An extra backslash is added to escape the original backslash. How do I remove this extra backslash?

Edit
Report

1 Answer

5

There is no extra backslash, it's just formatted that way in the interactive environment. Try:

print string

Then you can see that there really is no extra backslash.

answered 2010-02-01T19:41:40.620

Your Answer