To avoid a newline in multi-line strings

bearophile bearophileHUGS at lycos.com
Sat Jul 23 12:11:02 PDT 2011


Peter Alexander:

> Doesn't strip work?
> 
> auto s = strip("
> line 1
> line 2
> line 3
> ");

strip works, maybe even at compile-time for enum string literals.
With it you have to be a bit careful because if later you want to add leading spaces to the first line, they get removed.

The slash is used to not break the lines in the middle of the string too (this is a less common need):
string s = "verylongstring\
bar";

Bye,
bearophile


More information about the Digitalmars-d mailing list