Raw string "$"

Hello, I would like to print “abc$def” as a string

x = "abc$def"

but it doesn’t allow me because of the $, I tried to write it like this

x="abc"*raw"$"*"def"

but I get the following:

"abc\$def"

My issue is that I don’t want the diagonal (\) to appear, I just need the raw “$” . Is there any other way to do it?

Thank you so much!!

1 Like
> println("abc\$def")
abc$def 

? that’s what you want, no?

1 Like
julia> x="abc"*raw"$"*"def"
"abc\$def"

julia> println(x)
abc$def

Works perfectly for me! What’s the issue?

1 Like

$ is a special character in strings so it has to be escaped using \. It is used for string interpolation i.e

julia> a = 12.4
12.4
julia> "mynum = $a"
"mynum = 12.4"
2 Likes

Yes!!! I didn’t know that writing \ before $ would solve the issue. Thank you!!! :smiley:

1 Like

Thanks!!! I didn’t realize it was as simple as writing \ before the $, thank you!! :smiley:

3 Likes