String.Split Method
Identifies the substrings in this instance that are delimited by one or more characters specified in an array, then places the substrings into a String array.
Overload List
Identifies the substrings in this instance that are delimited by one or more characters specified in an array, then places the substrings into a String array.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function Split(ParamArray Char()) As String()
[C#] public string[] Split(params char[]);
[C++] public: String* Split(__wchar_t __gc[]) __gc[];
[JScript] public function Split(Char[]) : String[];
Identifies the substrings in this instance that are delimited by one or more characters specified in an array, then places the substrings into a String array. A parameter specifies the maximum number of array elements to return.
[Visual Basic] Overloads Public Function Split(Char(), Integer) As String()
[C#] public string[] Split(char[], int);
[C++] public: String* Split(__wchar_t __gc[], int) __gc[];
[JScript] public function Split(Char[], int) : String[];
Example
[Visual Basic, C#, C++] The following code example demonstrates how count affects the number of strings returned by Split.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of Split. For other examples that might be available, see the individual overload topics.
[Visual Basic] Imports System Imports Microsoft.VisualBasic _ Public Class StringSplit2 Public Shared Sub Main() Dim delimStr As String = " ,.:" Dim delimiter As Char() = delimStr.ToCharArray() Dim words As String = "one two,three:four." Dim split As String() = Nothing Console.WriteLine("The delimiters are -{0}-", delimStr) Dim x As Integer For x = 1 To 5 split = words.Split(delimiter, x) Console.WriteLine(ControlChars.Cr + "count = {0,2} ..............", x) Dim s As String For Each s In split Console.WriteLine("-{0}-", s) Next s Next x End Sub 'Main End Class 'StringSplit2 [C#] using System; public class StringSplit2 { public static void Main() { string delimStr = " ,.:"; char [] delimiter = delimStr.ToCharArray(); string words = "one two,three:four."; string [] split = null; Console.WriteLine("The delimiters are -{0}-", delimStr); for (int x = 1; x <= 5; x++) { split = words.Split(delimiter, x); Console.WriteLine("\ncount = {0,2} ..............", x); foreach (string s in split) { Console.WriteLine("-{0}-", s); } } } } [C++] #using <mscorlib.dll> using namespace System; using namespace System::Collections; int main() { String* delimStr = S" ,.:"; Char delimiter[] = delimStr->ToCharArray(); String* words = S"one two,three:four."; String* split[] = 0; Console::WriteLine(S"The delimiters are -{0}-", delimStr); for (int x = 1; x <= 5; x++) { split = words->Split(delimiter, x); Console::WriteLine(S"\ncount = {0, 2} ..............", __box(x)); IEnumerator* myEnum = split->GetEnumerator(); while (myEnum->MoveNext()) { String* s = __try_cast<String*>(myEnum->Current); Console::WriteLine(S"-{0}-", s); } } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.