How to replace \ by \\ in string

Hi guys:

I am using Julia on my windows computer. When I copy a path, it usually gives me like C:\Users\xxx\.... But julia will say invalid escape sequence and I need to replace all \ by \\. I want to know if there is a quick way to achieve this goal. Thanks.

You can use raw string literals:

julia> raw"C:\Users\xxx\..."

Yes this works. Thanks

I believe that if you already have the string, the proper way to do that is by using escape_string

1 Like

Yeah I think this is another way to this. But what’s the difference between the raw string and escape_string? Based on my test, the raw string gives me what I want.

I wouldn’t know exactly if there is much difference. I would say that use cases are different. I guess that is you want to use interpolation, escape_string is better, it has options too, so probably more flexible, at the cost of verbosity.