Single string on multiple lines without `\n`


#1

Is there a way to continue a single string on multiple lines without inserting \n into the string?

For example

"a#some character here
b"
"ab"

The only methods I currently know of is

string("a",
    "b")

I was wondering if there was an even more succinct shortcut.


#2
julia> """a
       b
       c
       """
"a\nb\nc\n"

Edit: uh… that’s not what you were asking for. I don’t think you can do that with a single string literal, no.


#3

What I meant was, can I type the string on multiple lines (for code formatting purposes) without there being any \n in the string?


#4

Technically

julia> "a"*
       "b"*
       "c"
"abc"

is more succinct. Otherwise see my edit above :wink:


#5

Wow I feel really stupid for not having realized that, thanks.

In retrospect, what I was looking for was not necessarily something more “succinct”, but something for which I wouldn’t have to stick string into the first line forcing me to reformat everything, your solution satisfies that, thanks.


#6

Alternatively:

macro W_str(s)
    :(replace($(esc(s)), r"\n+" => " "))
end
julia> W"""
       a
       b
       c
       """
"a b c "