By default, or when Limit equals -1, the Split function splits the input string at every occurrence of the delimiter string, and returns the substrings in an array. When the Limit parameter is greater than zero, the Split function splits the string at the first Limit-1 occurrences of the delimiter, and returns an array with the resulting substrings. For example, Split("a:b:c", ":") returns the array {"a", "b", "c"}, while Split("a:b:c", ":", 2) returns the array {"a", "b:c"}.
When the Split function encounters two delimiters in a row, or a delimiter at the beginning or end of the string, it interprets them as surrounding an empty string (""). For example, Split("xx", "x") returns the array containing three empty strings: one from between the beginning of the string and the first "x", one from between the two "x" strings, and one from between the last "x" and the end of the string.
This table demonstrates how the optional Delimiter, Limit, and Compare parameters can change the behavior of the Split function.
|
Split Call
|
Return Value
|
| Split("42, 12, 19") | {"42," , "12," , "19"} |
| Split("42, 12, 19", ", ") | {"42", "12", "19"} |
| Split("42, 12, 19", ", ", 2) | {"42", "12, 19"} |
| Split("192.168.0.1", ".") | {"192", "168", "0", "1"} |
| Split("Alice and Bob", " AND ") | {"Alice and Bob"} |
| Split("Alice and Bob", " AND ", ,CompareMethod.Text) | {"Alice", "Bob"} |
| Split("someone@example.com", "@",1) | {"someone@example.com"} |
| Split("someone@example.com", "@",2) | {"someone", "example.com"} |