Delimiter characters are not included in the elements of the return value array. Delimiters are detected using an ordinal comparison.
If this instance does not contain any of the characters in separator, the return value array consists of a single element that contains this instance. If the separator parameter is a null reference (Nothing in Visual Basic) or contains no characters, white space characters are assumed to be the delimiters.
If two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance, the corresponding array element contains Empty.
For example:
| Input | separator | Output |
| "42, 12, 19" | new Char[] {',', ' '} | {"42", "", "12", "", "19"} |
| "42..12..19" | new Char[] {'.'} | {"42", "", "12", "", "19"} |
| "Banana" | new Char[] {'.'} | {"Banana"} |
| "Darb\nSmarba" | new Char[] {} | {"Darb", "Smarba"} |
| "Darb\nSmarba" | null | {"Darb", "Smarba"} |
Performance Considerations
The Split methods allocate memory for the return value array object and a String object for each array element. If managing memory allocation is critical in your application, consider using the IndexOfAny method, and optionally the Compare method, to locate a substring within a string.
If you are splitting a string at a separator character, use the IndexOfAny method to locate a separator character in the string. If you are splitting a string at a separator string, use the IndexOfAny method to locate the first character of a separator string. Then use the Compare method to determine whether the characters after that first character are equal to the remaining characters of the separator string.