Reading unicode string with readf ("%s")

Ivan Kazmenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 4 10:09:47 PST 2014


On Monday, 3 November 2014 at 20:10:02 UTC, Gary Willoughby wrote:
> On Monday, 3 November 2014 at 19:47:17 UTC, Ivan Kazmenko wrote:
>> So, if there is an idiomatic way to read the whole file into a 
>> string which is Unicode-compatible, it would be great to learn 
>> that, too.
>
> Maybe something like this:
>
> import std.stdio;
> import std.array;
> import std.conv;
>
> string text = stdin
> 	.byLine(KeepTerminator.yes)
> 	.join()
> 	.to!(string);

And thanks for a short alternative!

At first glance, looks like it sacrifices a bit of efficiency on 
the way: the "remove-line-breaks, then add-line-breaks" path 
looks redundant.
Still, it does not store intermediate splitted representation, so 
the inefficiency is in fact not catastrophic, right?


More information about the Digitalmars-d-learn mailing list