How to do escape_string

To assign that string to a variable in Julia, you have two options. Either you manually escape each slash by doubling it…

mypath = "C:\\Users\\User\\Dropbox\\codes\\JULIA\\stock1\\TRAINING\\IBM.csv"

or you use raw string…

mypath = raw"C:\Users\User\Dropbox\codes\JULIA\stock1\TRAINING\IBM.csv"

In Julia string literals, the backslash has special meaning so that you can add non-printable characters (such as the newline) or, include the double quote.

julia> print("The sun came over the horizon.\nHe said: \"Beautiful!\"")
The sun came over the horizon.
He said: "Beautiful!"

This is why using slash in a string literal is complex. So, to actually include a slash in your output string, you have to double it.

Anyway, I’d avoid eval and Meta.parse – it’s exceptionally rare you’d ever need to use them. I’ve been using Julia for years in some complicated works and have found only a few cases where Meta.parse and eval were indicated.

2 Likes