"strtok" D equivalent

rikki cattermole rikki at cattermole.co.nz
Thu Jul 28 19:37:31 UTC 2022


I don't know of a D version, although it should be pretty easy to write 
up yourself.

But you can always use strtok itself.

https://github.com/dlang/dmd/blob/09d04945bdbc0cba36f7bb1e19d5bd009d4b0ff2/druntime/src/core/stdc/string.d#L97

Very similar to example given on the docs:

```d
void main()
{
     import std.stdio, std.algorithm;
     string input = "one + two * (three - four)!";
     string delimiters = "!+-(*)";

     foreach(value; input.splitWhen!((a, b) => delimiters.canFind(b))) {
         writeln(value);
     }
}
```


More information about the Digitalmars-d-learn mailing list