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

2015-01-09 Thread ketmar via Digitalmars-d-learn
On Fri, 09 Jan 2015 15:36:21 + FrankLike via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 9 January 2015 at 14:03:21 UTC, ketmar via Digitalmars-d-learn wrote: On Fri, 09 Jan 2015 13:54:00 + Robert burner Schadek via Digitalmars-d-learn

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

2015-01-09 Thread FrankLike via Digitalmars-d-learn
On Friday, 9 January 2015 at 15:57:21 UTC, ketmar via Digitalmars-d-learn wrote: On Fri, 09 Jan 2015 15:36:21 + FrankLike via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 9 January 2015 at 14:03:21 UTC, ketmar via Digitalmars-d-learn wrote: On Fri, 09 Jan

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

2015-01-09 Thread FrankLike via Digitalmars-d-learn
On Friday, 9 January 2015 at 14:03:21 UTC, ketmar via Digitalmars-d-learn wrote: On Fri, 09 Jan 2015 13:54:00 + Robert burner Schadek via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 9 January 2015 at 13:25:17 UTC, ketmar via Digitalmars-d-learn wrote: if you

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

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

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

2015-01-09 Thread ketmar via Digitalmars-d-learn
On Fri, 09 Jan 2015 09:36:01 + FrankLike via Digitalmars-d-learn digitalmars-d-learn@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

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

2015-01-09 Thread Robert burner Schadek via Digitalmars-d-learn
On Friday, 9 January 2015 at 14:03:21 UTC, ketmar via Digitalmars-d-learn wrote: std.regex can use CTFE to compile regular expressions (yet it sometimes slower than non-CTFE variant), and i mean that we compile regexp before doing alot of searches, not before each single search. if you have

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

2015-01-09 Thread ketmar via Digitalmars-d-learn
On Fri, 09 Jan 2015 14:11:49 + Robert burner Schadek via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 9 January 2015 at 14:03:21 UTC, ketmar via Digitalmars-d-learn wrote: std.regex can use CTFE to compile regular expressions (yet it sometimes slower

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

2015-01-09 Thread Robert burner Schadek via Digitalmars-d-learn
On Friday, 9 January 2015 at 13:25:17 UTC, ketmar via Digitalmars-d-learn wrote: if you *really* concerned with speed here, you'd better consider using regular expressions. as regular expression can be precompiled and then search for multiple words with only one pass over the source string. i

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

2015-01-09 Thread ketmar via Digitalmars-d-learn
On Fri, 09 Jan 2015 13:54:00 + Robert burner Schadek via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 9 January 2015 at 13:25:17 UTC, ketmar via Digitalmars-d-learn wrote: if you *really* concerned with speed here, you'd better consider using regular

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

2015-01-09 Thread FrankLike via Digitalmars-d-learn
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

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

2015-01-09 Thread ketmar via Digitalmars-d-learn
On Fri, 09 Jan 2015 12:46:53 + FrankLike via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: The code is the best,and it's better than indexOfAny in C#: import std.algorithm, std.stdio; void main () { auto places = [ home, office, sea,plane]; auto strWhere = He

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

2015-01-09 Thread FrankLike via Digitalmars-d-learn
On Friday, 9 January 2015 at 10:02:53 UTC, ketmar via Digitalmars-d-learn wrote: 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 {

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

2015-01-09 Thread ketmar via Digitalmars-d-learn
On Fri, 09 Jan 2015 13:06:09 + FrankLike via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 9 January 2015 at 10:02:53 UTC, ketmar via Digitalmars-d-learn wrote: import std.algorithm, std.stdio; void main () { string s = he is at home; if

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

2015-01-09 Thread Robert burner Schadek via Digitalmars-d-learn
On Friday, 9 January 2015 at 14:21:04 UTC, ketmar via Digitalmars-d-learn wrote: heh. regexps *are* fast enough. it's hard to beat well-optimised generated thingy on a complex grammar. ;-) I don't see your point, anyway I think he got his help or at least some help.

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

2015-01-08 Thread FrankLike via Digitalmars-d-learn
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

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

2015-01-08 Thread ketmar via Digitalmars-d-learn
On Fri, 09 Jan 2015 07:10:14 + 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

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

2015-01-08 Thread FrankLike via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 17:08:55 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Try this: http://dlang.org/phobos-prerelease/std_algorithm#.findAmong T You mean ? The result is not that I want to get! ---test.d-- import std.stdio,

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

2015-01-08 Thread FrankLike via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 17:08:55 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Try this: http://dlang.org/phobos-prerelease/std_algorithm#.findAmong T Thank you,it can work. but it's not what I want. ---test.d-- import std.stdio,

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

2015-01-08 Thread Robert burner Schadek via Digitalmars-d-learn
use canFind like such: bool a = canFind(strs,s) = 1; let the compiler figger out what the types of the parameter are.

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

2015-01-07 Thread bearophile via Digitalmars-d-learn
FrankLike: But now I want to know in a string (like hello.exe or hello.a,or hello.dll or hello.lib ) whether contains any of them: [exe,dll,a,lib]. Seems this: http://rosettacode.org/wiki/File_extension_is_in_extensions_list#D Bye, bearophile

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

2015-01-07 Thread FrankLike via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 15:11:57 UTC, John Colvin wrote: On Wednesday, 7 January 2015 at 14:54:51 UTC, FrankLike wrote: I want to know whether the string strs contains 'exe','dll','a','lib',in c#, I can do : int index = indexofany(strs,[exe,dll,a,lib]); but in D: I must to do like

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

2015-01-07 Thread FrankLike via Digitalmars-d-learn
I want to know whether the string strs contains 'exe','dll','a','lib',in c#, I can do : int index = indexofany(strs,[exe,dll,a,lib]); but in D: I must to do like this: findStr(strs,[exe,lib,dll,a])) bool findStr(string strIn,string[] strFind) { bool bFind = false;

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

2015-01-07 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 14:54:51 UTC, FrankLike wrote: I want to know whether the string strs contains 'exe','dll','a','lib',in c#, I can do : int index = indexofany(strs,[exe,dll,a,lib]); but in D: I must to do like this: findStr(strs,[exe,lib,dll,a])) bool findStr(string

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

2015-01-07 Thread FrankLike via Digitalmars-d-learn
std.algorithm.find has several overloads, one of which takes multiple needles. The same is true for std.algorithm.canFind Quoting from the relevant std.algorithm.find overload docs: Finds two or more needles into a haystack. string strs =hello.exe; string[] s =[lib,exe,a,dll]; auto a =

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

2015-01-07 Thread H. S. Teoh via Digitalmars-d-learn
Try this: http://dlang.org/phobos-prerelease/std_algorithm#.findAmong T -- MACINTOSH: Most Applications Crash, If Not, The Operating System Hangs

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

2015-01-07 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 15:57:18 UTC, FrankLike wrote: On Wednesday, 7 January 2015 at 15:11:57 UTC, John Colvin wrote: On Wednesday, 7 January 2015 at 14:54:51 UTC, FrankLike wrote: I want to know whether the string strs contains 'exe','dll','a','lib',in c#, I can do : int index =

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

2015-01-07 Thread Tobias Pankrath via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 16:02:25 UTC, bearophile wrote: FrankLike: But now I want to know in a string (like hello.exe or hello.a,or hello.dll or hello.lib ) whether contains any of them: [exe,dll,a,lib]. Seems this: http://rosettacode.org/wiki/File_extension_is_in_extensions_list#D