Search a file skiping whitespace

Johann MacDonagh johann.macdonagh.no at spam.gmail.com
Sat Jul 16 13:00:26 PDT 2011


On 7/16/2011 3:56 PM, Johann MacDonagh wrote:
> On 7/16/2011 3:05 PM, Willy Martinez wrote:
>> Any help?
>
> import std.algorithm;
> import std.ascii;
> import std.stdio;
>
> void main(string[] argv)
> {
> auto s = "71104 08924 72394 13995 49707 98696
> 48245 08311 44066 67172 56025 07952
> 00384 37808 90166 13871 94258 37216";
>
> auto t = filter!("!std.ascii.isWhite(a)")(s);
>
> bool found = canFind(t, "408");
>
> writeln(t);
> writeln(found);
> }
>
> Outputs:
>
> 711040892472394139954970798696482450831144066671725602507952003843780890166138719425837216
>
> true
>

This is actually better:

import std.algorithm;
import std.ascii;
import std.stdio;

void main(string[] argv)
{
     auto s = "71104 08924 72394 13995 49707 98696
48245 08311 44066 67172 56025 07952
00384 37808 90166 13871 94258 37216";

     auto t = filter!( (c) { return isWhite(c); } )(s);

     bool found = canFind(t, "408");

     writeln(t);
     writeln(found);
}

Otherwise we're relying on std.algorithm importing std.ascii.


More information about the Digitalmars-d-learn mailing list