How to unescape special characters in Rust?

291 Views Asked by At

For example, if you have escaped string like Hello wo\\\\rld.txt you want to unescape it and make it, Hello wo\\rld.txt

essentially making, \\ -> \, \\r -> \r, \\n -> \n, etc

I tried doing string replace like:

out = out.replace("\\", "\"); but that is syntax error

1

There are 1 best solutions below

2
cafce25 On

You still have to escape every \ in your string literals i.e. out = out.replace("\\\\", "\\");