View source code
Display the source code in std/string.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.string.munch
Finds the position pos of the first character in s
that does not match pattern
(in the terminology used by
inPattern
). Updates s
=
s
[pos..$]. Returns the slice from the beginning of the original
(before update) string up to, and excluding, pos.
The munch
function is mostly convenient for skipping
certain category of characters (e.g. whitespace) when parsing
strings. (In such cases, the return value is not used.)
Prototype
S1 munch(S1, S2)( S1 s, S2 pattern ) pure @nogc @safe;
Example
string s = "123abc"; string t = munch(s, "0123456789"); assert(t == "123" && s == "abc"); t = munch(s, "0123456789"); assert(t == "" && s == "abc");
Authors
Walter Bright, Andrei Alexandrescu, and Jonathan M Davis