What token to separate the input string into words with.
Input string of words separated by separator.
Variadic list of strings to assign the split words in slice.
A SplitResults with the results of the split attempt.
1 import lu.conv : Enum; 2 3 { 4 string line = "abc def ghi"; 5 string abc, def, ghi; 6 immutable results = line.splitInto(abc, def, ghi); 7 8 assert((abc == "abc"), abc); 9 assert((def == "def"), def); 10 assert((ghi == "ghi"), ghi); 11 assert(!line.length, line); 12 assert((results == SplitResults.match), Enum!SplitResults.toString(results)); 13 } 14 { 15 string line = "abc def ghi"; 16 string abc, def, ghi; 17 immutable results = line.splitInto(abc, def, ghi); 18 19 assert((abc == "abc"), abc); 20 assert((def == "def"), def); 21 assert((ghi == "ghi"), ghi); 22 assert(!line.length, line); 23 assert((results == SplitResults.match), Enum!SplitResults.toString(results)); 24 } 25 { 26 string line = "abc_def ghi"; 27 string abc, def, ghi; 28 immutable results = line.splitInto!"_"(abc, def, ghi); 29 30 assert((abc == "abc"), abc); 31 assert((def == "def ghi"), def); 32 assert(!ghi.length, ghi); 33 assert(!line.length, line); 34 assert((results == SplitResults.underrun), Enum!SplitResults.toString(results)); 35 } 36 { 37 string line = "abc def ghi"; 38 string abc, def; 39 immutable results = line.splitInto(abc, def); 40 41 assert((abc == "abc"), abc); 42 assert((def == "def"), def); 43 assert((line == "ghi"), line); 44 assert((results == SplitResults.overrun), Enum!SplitResults.toString(results)); 45 } 46 { 47 string line = "abc///def"; 48 string abc, def; 49 immutable results = line.splitInto!"//"(abc, def); 50 51 assert((abc == "abc"), abc); 52 assert((def == "/def"), def); 53 assert(!line.length, line); 54 assert((results == SplitResults.match), Enum!SplitResults.toString(results)); 55 } 56 { 57 string line = "abc 123 def I am a fish"; 58 string abc, a123, def; 59 immutable results = line.splitInto(abc, a123, def); 60 61 assert((abc == "abc"), abc); 62 assert((a123 == "123"), a123); 63 assert((def == "def"), def); 64 assert((line == "I am a fish"), line); 65 assert((results == SplitResults.overrun), Enum!SplitResults.toString(results)); 66 } 67 { 68 string line; 69 string abc, def; 70 immutable results = line.splitInto(abc, def); 71 assert((results == SplitResults.underrun), Enum!SplitResults.toString(results)); 72 }
Splits a string by a passed separator and assign the delimited words to the passed strings by ref.
Note: Does *not* take quoted substrings into consideration.