On Fri, 09 Jan 2015 07:10:14 +0000
FrankLike via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> On Thursday, 8 January 2015 at 15:15:59 UTC, Robert burner 
> Schadek wrote:
> >
> > use canFind like such:
> >     bool a = canFind(strs,s) >= 1;
> >
> > let the compiler figger out what the types of the parameter are.
> 
> canFind is work for such as :
>   bool x = canFind(["exe","lib","a","dll"],"a" );
> but can't work for canFind(["exe","lib","a","dll"],"hello.lib");
> 
> So  I very want to let the function 'indexOfAny' do the same work.
> 
> Thank you.
> 
> Frank
be creative! ;-)

  import std.algorithm, std.stdio;

  void main () {
    string fname = "hello.exe";
    import std.path : extension;
    if (findAmong([fname.extension], [".exe", ".lib", ".a", ".dll"]).length) {
      writeln("got it!");
    } else {
      writeln("alas...");
    }
  }

note the dots in extension list.

yet you can do it even easier:

  import std.algorithm, std.stdio;

  void main () {
    string fname = "hello.exe";
    import std.path : extension;
    if ([".exe", ".lib", ".a", ".dll"].canFind(fname.extension)) {
      writeln("got it!");
    } else {
      writeln("alas...");
    }
  }

as you obviously interested in extension here -- check only that
part! ;-)

Attachment: signature.asc
Description: PGP signature

Reply via email to