Small problem with multi-line strings

bearophile bearophileHUGS at lycos.com
Thu Jul 21 16:18:14 PDT 2011


Multi-line strings are handy, but I have a small problem.

This is an example, it has a problem, there is an unwanted newline at the beginning:

writeln("
- First item:  150
- Second item: 200
- Third item:  105");


To avoid it you can write this, but both break the alignment in the source code, and it's not nice looking:

writeln("- First item:  150
- Second item: 200
- Third item:  105");


writeln(
"- First item:  150
- Second item: 200
- Third item:  105");


To solve this problem in Python you are allowed to write (in Python you need tree " or tree ' to denote a multi-line string):

print """\
- First item:  150
- Second item: 200
- Third item:  105"""


The extra slash at the beginning avoids the start newline.

Is this currently possible in D too? If this isn't possible, is it worth a very little enhancement request for the support of that syntax?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list