Small problem with multi-line strings

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Jul 22 03:30:53 PDT 2011


On 22.07.2011 3:18, bearophile wrote:
> 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
How about:

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

Yeah, I know implicit concatenation is bad and I would agree once ~ 
concatenate complie-time string for 0 overhead.
After all, hardcoded strings are not exactly good thing in the first place.
For big formatted texts just use string import :
      writeln(import("usage.txt"));
work like a charm.
So IMHO it's a non-issue.

-- 
Dmitry Olshansky



More information about the Digitalmars-d-learn mailing list