the string to split by word if no separator is given
An array containing the divided parts of range (or the words of s).
import std.uni : isWhite; assert("Learning,D,is,fun".split(",") == ["Learning", "D", "is", "fun"]); assert("Learning D is fun".split!isWhite == ["Learning", "D", "is", "fun"]); assert("Learning D is fun".split(" D ") == ["Learning", "is fun"]);
string str = "Hello World!"; assert(str.split == ["Hello", "World!"]); string str2 = "Hello\t\tWorld\t!"; assert(str2.split == ["Hello", "World", "!"]);
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]]);
std.algorithm.iteration.splitter for a lazy version without allocating memory.
std.regex.splitter for a version that splits using a regular expression defined separator.
Eagerly splits range into an array, using sep as the delimiter.
When no delimiter is provided, strings are split into an array of words, using whitespace as delimiter. Runs of whitespace are merged together (no empty words are produced).
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.