diff --git a/std/array.d b/std/array.d index e3d94ad17ae..33b731782d2 100644 --- a/std/array.d +++ b/std/array.d @@ -1363,6 +1363,9 @@ $(D @safe), $(D pure) and $(D CTFE)-able. Params: s = the string to split +Returns: + An array of each word in `s` + See_Also: $(REF splitter, std,algorithm,iteration) for a version that splits using any separator. @@ -1402,6 +1405,29 @@ if (isSomeString!S) return result; } +/// +@safe unittest +{ + string str = "Hello World!"; + assert(str.split == ["Hello", "World!"]); + + string str2 = "Hello\t\tWorld\t!"; + assert(str2.split == ["Hello", "World", "!"]); +} + +/** + * `split` allocates memory, so the same effect can be achieved lazily + * using $(REF splitter, std,algorithm,iteration). + */ +@safe unittest +{ + import std.ascii : isWhite; + import std.algorithm.comparison : equal; + + string str = "Hello World!"; + assert(str.splitter!(isWhite).equal(["Hello", "World!"])); +} + @safe unittest { import std.conv : to;