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

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 9 02:02:28 PST 2015


On Fri, 09 Jan 2015 09:36:01 +0000
FrankLike via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> 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.
be creative! ;-)

  import std.algorithm, std.stdio;

  void main () {
    string s = "he is at plane";
    if (findAmong!((string a, string b) => b.canFind(a))([s], ["home", "office", "sea", "plane"]).length) {
      writeln("got it!");
    } else {
      writeln("alas...");
    }
  }

or:

  import std.algorithm, std.stdio;

  void main () {
    string s = "he is at home";
    if (["home", "office", "sea", "plane"].canFind!((a, string b) => b.canFind(a))(s)) {
      writeln("got it!");
    } else {
      writeln("alas...");
    }
  }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150109/0b1ffb9b/attachment.sig>


More information about the Digitalmars-d-learn mailing list