View source code Display the source code in std/array.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.

std.array.split - multiple declarations

Function split

Eagerly split the string s into an array of words, using whitespace as delimiter. Runs of whitespace are merged together (no empty words are produced).

@safe, pure and CTFE-able.

Prototype

S[] split(S)(
  S s
) pure @safe
if (isSomeString!S);

See Also

std.algorithm.iteration.splitter for a version that splits using any separator.

std.regex.splitter for a version that splits using a regular expression defined separator.

Example

assert(split("hello world") == ["hello","world"]);
assert(split("192.168.0.1", ".") == ["192", "168", "0", "1"]);

auto a = split([1, 2, 3, 4, 5, 1, 2, 3, 4, 5], [2, 3]);
assert(a == [[1], [4, 5, 1], [4, 5]]);

Function split

Eagerly splits range into an array, using sep as the delimiter.

The range must be a forward range. The separator can be a value of the same type as the elements in range or it can be another forward range.

Prototypes

auto split(Range, Separator)(
  Range range,
  Separator sep
)
if (isForwardRange!Range && is(typeof(ElementType!Range.init == Separator.init)));

auto split(Range, Separator)(
  Range range,
  Separator sep
)
if (isForwardRange!Range && isForwardRange!Separator && is(typeof(ElementType!Range.init == ElementType!Separator.init)));

auto split(alias isTerminator, Range)(
  Range range
)
if (isForwardRange!Range && is(typeof(unaryFun!isTerminator(range.front))));

Examples

If range is a string, sep can be a char or another string. The return type will be an array of strings. If range is an int array, sep can be an int or another int array. The return type will be an array of int arrays.

Parameters

NameDescription
range a forward range.
sep a value of the same type as the elements of range or another forward range.

Returns

An array containing the divided parts of range.

See Also

std.algorithm.iteration.splitter for the lazy version of this function.

Authors

Andrei Alexandrescu and Jonathan M Davis

License

Boost License 1.0.

Comments