Why do the same work about 'IndexOfAny' and 'indexOf' function?

FrankLike via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 9 01:36:01 PST 2015


iday, 9 January 2015 at 07:41:07 UTC, ketmar via 
Digitalmars-d-learn wrote:
> On Fri, 09 Jan 2015 07:10:14 +0000
> FrankLike via Digitalmars-d-learn 
> <digitalmars-d-learn at 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! ;-)

Sorry,it's  only  a example .Thank  you  work  hard,but  it's  
not  what  I  want.
'indexOfAny '  function  should  do  this  work.
”he  is  at  home"  ,["home","office",”sea","plane"],  in  
C#,IndexOfAny can do it,what  about  in D?
I know  findAmong can do it,but  use  two  function  .
Thank  you.


More information about the Digitalmars-d-learn mailing list