Thread overview
Quotes inside wysiwyg strings, or alternative solution?
Jul 18, 2019
Paul
Jul 18, 2019
Dennis
Jul 18, 2019
Paul
July 18, 2019
Hi,

I have searched, but can't find a solution. In C++ and Rust there is the option of enclosing a string in a sequence of chars (after R/r) to allow quotation marks in multiline string literals.

What is the solution in D for wysiwyg strings (or similar) spanning multiple lines containing quotes and apostrophes?

Thanks!

(also, how can I put formatted code in a post?)
July 18, 2019
On Thursday, 18 July 2019 at 11:38:55 UTC, Paul wrote:
> What is the solution in D for wysiwyg strings (or similar) spanning multiple lines containing quotes and apostrophes?

Take a look at:
https://dlang.org/spec/lex.html#string_literals

All string literals may span multiple lines.

If you only need " and ' without `, you can use a string literal like this: `WysiwygCharacters`

For ' and ` in your string you can use r"WysiwygCharacters".

You can also concatenate different string literals with ~.

If your string contains code, you can try a token string like q{if 'a' "" ``}

Finally, you can also have custom delimiters in q-strings but I don't recommend them since they're hard to process for text editors. (Details are in the spec)

> (also, how can I put formatted code in a post?)

Often requested, but you can't.
July 18, 2019
> All string literals may span multiple lines.

Ah, I didn't know that. Thanks for the detailed reply!