Triple double quote not acting as expected



“”"I am a “string” “”"
works OK - notice the space

“”“I am a “string””""
does not work - julia expects yet another closing double quote
this seems strange to me!

“”“I am a “string” “””"
this works OK, but has (as far as I understand the theory) one closing double quote too much …

What am I missing?


You need to escape quotation marks in a string with a backslash:

"""I am a \"string\""""

Edit: sorry, I guess from you would think that """I am a "string"""" should work too.

The behavior is different on latest master:

julia> """I am a "string""""
ERROR: syntax: cannot juxtapose string literal

which was a result of


Julia only looks at the triple as an end-marker — the parser isn’t keeping track of open/close “…” pairs inside the triple. Need to escape the first in the ending “”"" sequence.


"""I am a "string"""" is being parsed as """I am a "string""" followed by a ", and that is why (as at-ihnorton) said, the first " in the final sequence needs to be quoted.
If you have wish to have more than 2 " in a row in a triple-quoted string, then you need to use \ on every 3rd one, for example, to have 6 " inside a triple-quoted string, you’d need to have ""\"""\".


That’s what I realized later. Thx to all!