# How to replace \\ by \\\\ in string

**URL:** <https://discourse.julialang.org/t/how-to-replace-by-in-string/82602>\
**Category:** New to Julia\
**Tags:** strings\
**Created:** [June 11, 2022, 2:48pm UTC](https://discourse.julialang.org/t/how-to-replace-by-in-string/82602 "2022-06-11T14:48:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jisutich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jisutich/32/33342_2.png) [@jisutich](https://discourse.julialang.org/u/jisutich)\
**Post date:** [June 11, 2022, 2:48pm UTC](https://discourse.julialang.org/t/how-to-replace-by-in-string/82602/1 "2022-06-11T14:48:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [June 11, 2022, 2:51pm UTC](https://discourse.julialang.org/t/how-to-replace-by-in-string/82602/2 "2022-06-11T14:51:46Z")

</div>

You can use [raw string literals](https://docs.julialang.org/en/v1/manual/strings/#man-raw-string-literals):

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

```

---

<div class="post-metadata">

**Author:** ![jisutich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jisutich/32/33342_2.png) [@jisutich](https://discourse.julialang.org/u/jisutich)\
**Post date:** [June 11, 2022, 2:53pm UTC](https://discourse.julialang.org/t/how-to-replace-by-in-string/82602/3 "2022-06-11T14:53:58Z")

</div>

> [@giordano](#):
>
> `raw"C:\Users\xxx\..."`

Yes this works. Thanks

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [June 11, 2022, 9:00pm UTC](https://discourse.julialang.org/t/how-to-replace-by-in-string/82602/4 "2022-06-11T21:00:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jisutich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jisutich/32/33342_2.png) [@jisutich](https://discourse.julialang.org/u/jisutich)\
**Post date:** [June 12, 2022, 8:38pm UTC](https://discourse.julialang.org/t/how-to-replace-by-in-string/82602/5 "2022-06-12T20:38:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [June 12, 2022, 9:36pm UTC](https://discourse.julialang.org/t/how-to-replace-by-in-string/82602/6 "2022-06-12T21:36:10Z")

</div>

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.
