Does System.String.Split()
ever return null
? (.NET)
I know I've been coding in the belief that it does not, however, upon reading the docs I do not see such a statement. Since there is no such a statement in the docs, so I want to ask in the experience of the community has anyone actually encountered the case that string.Split
returns null
?
The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
The split() method does not change the value of the original string. If the delimiter is an empty string, the split() method will return an array of elements, one element for each character of string. If you specify an empty string for string, the split() method will return an empty string and not an array of strings.
split (separator, limit) , if the separator is not in the string, it returns a one-element array with the original string in it.
In C#, Split() is a string class method. The Split() method returns an array of strings generated by splitting of original string separated by the delimiters passed as a parameter in Split() method. The delimiters can be a character or an array of characters or an array of strings.
No, it cannot return null. If you look at the source of it, it even guarantees it with code contracts:
public String[] Split(params char[] separator) { Contract.Ensures(Contract.Result<String[]>() != null);
All public overloads also make the same guarantee.
No, it doesn't return null. If the separator is not present, it returns the whole string
From MSDN
If this instance does not contain any of the strings in separator, the returned array consists of a single element that contains this instance. If the separator parameter is null or contains no characters, white-space characters are assumed to be the delimiters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With