Re: "strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn
On Thursday, 28 July 2022 at 23:16:15 UTC, Paul Backus wrote: On Thursday, 28 July 2022 at 21:52:28 UTC, pascal111 wrote: On Thursday, 28 July 2022 at 20:36:31 UTC, Paul Backus wrote: ```d import std.algorithm: filter; import std.range: empty; import std.functional: not; // ... auto

Re: "strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn
On Thursday, 28 July 2022 at 23:16:15 UTC, Paul Backus wrote: On Thursday, 28 July 2022 at 21:52:28 UTC, pascal111 wrote: On Thursday, 28 July 2022 at 20:36:31 UTC, Paul Backus wrote: ```d import std.algorithm: filter; import std.range: empty; import std.functional: not; // ... auto

Re: "strtok" D equivalent

2022-07-28 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 28 July 2022 at 21:52:28 UTC, pascal111 wrote: On Thursday, 28 July 2022 at 20:36:31 UTC, Paul Backus wrote: ```d import std.algorithm: filter; import std.range: empty; import std.functional: not; // ... auto tokens = input .splitter!(c => delimiters.canFind(c))

Re: "strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn
On Thursday, 28 July 2022 at 20:36:31 UTC, Paul Backus wrote: On Thursday, 28 July 2022 at 19:17:26 UTC, pascal111 wrote: What's the "strtok" - C function - D equivalent? https://en.cppreference.com/w/cpp/string/byte/strtok Closest thing is probably `std.algorithm.splitter` with a

Re: "strtok" D equivalent

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 09:03:55PM +, pascal111 via Digitalmars-d-learn wrote: > On Thursday, 28 July 2022 at 19:37:31 UTC, rikki cattermole wrote: [...] > > foreach(value; input.splitWhen!((a, b) => delimiters.canFind(b))) { > > writeln(value); > > } > > } > > ``` > > From

Re: "strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn
On Thursday, 28 July 2022 at 19:37:31 UTC, rikki cattermole wrote: 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.

Re: "strtok" D equivalent

2022-07-28 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 28 July 2022 at 19:17:26 UTC, pascal111 wrote: What's the "strtok" - C function - D equivalent? https://en.cppreference.com/w/cpp/string/byte/strtok Closest thing is probably `std.algorithm.splitter` with a predicate: ```d import std.algorithm: splitter, canFind; import

Re: "strtok" D equivalent

2022-07-28 Thread rikki cattermole via Digitalmars-d-learn
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