n ocurrance in a string
BCS
nothing at pathlink.com
Tue Jan 2 20:38:32 PST 2007
Heinz wrote:
> Hi,
>
> I'm doing a bit of work with strings. There's a function called find in
> std.string. This function returns the first ocurrance of a substring in a
> string, but how can i get the second, thrith, fifth...Nth ocurrance?
> Thanks a lot.
slice off the front:
char[] string = ...
int i = FindInString(string, "whatever");
i++;
i += FindInString(string[i..$], "whatever");
You may want to change this a bit for checking the return value (test of
no matche) and starting then next search more than one part the last (to
avoid overlapping matches.
More information about the Digitalmars-d-learn
mailing list