Creates an array of strings by splitting this string with a specified arrays as the separator.
[Visual Basic] Overloads Public Function Split( _ ByVal separator() As Char, _ ByVal count As Integer _ ) As String () [C#] public string[] Split( char[] separator, int count ); [C++] public: String* Split( __wchar_t* separator[], int count ) []; [JScript] public function Split( separator : Char[], count : int ) : String[];
Value | Condition |
---|---|
An array containing the substrings of this string | If they are separated by the separating string. |
A one element array that holds Empty | If this instance is an empty string. |
Exception Type | Condition |
---|---|
ArgumentException | If the separating string is null. |
ArgumentOutOfRangeException | If the count is negative. |
The separator is searched for and, if found, the substring preceding the occurrence is stored as the first element in the array of strings. We then continue in this manner by searching the substring that follows the occurrence.
On the other hand, if the separator is not found, the array of strings will contain this instance as its only element.
If the separator is the empty string (i.e., Empty), then the whitespace (i.e., IsWhiteSpace) is used as the separator.
When there are more than count different strings, the last n- (count-1) elements are concatenated and added as the last string. n represents the number of substrings in this instance.
"42, 12, 19".Split ({',', ' '}, 2) => {"42", "12, 19"} "42..12..19".Split({'.'}, 4) => {"42", "", "12", ".19"} "Banana".Split({'.'}, 2) => {"Banana"} "Darb Smarba".Split({}, 1) => {"Darb Smarba"} "Darb Smarba".Split(null,2) => {"Darb", "Smarba"} "Darb Smarba".Split(null,100) => {"Darb", "Smarba"} Throws ArgumentException if count is < 0.
String Class | String Members | System Namespace | String.Split Overload List | Char | Array | Int32