NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

String.Split (Char[], Int32)

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[];

Parameters

separator
The string used as the separator.
count
The maximum number of elements allowed in the array.

Return Value

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.

Exceptions

Exception Type Condition
ArgumentException If the separating string is null.
ArgumentOutOfRangeException If the count is negative.

Remarks

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.

Example

"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.

See Also

String Class | String Members | System Namespace | String.Split Overload List | Char | Array | Int32