Share via


Split Method (Char[], Int32)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Returns a string array that contains the substrings in this instance that are delimited by elements of a specified Unicode character array. A parameter specifies the maximum number of substrings to return.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Function Split ( _
    separator As Char(), _
    count As Integer _
) As String()
public string[] Split(
    char[] separator,
    int count
)
public:
array<String^>^ Split(
    array<wchar_t>^ separator, 
    int count
)
member Split : 
        separator:char[] * 
        count:int -> string[] 
public function Split(
    separator : char[], 
    count : int
) : String[]

Parameters

  • separator
    Type: array<System. . :: . .Char> [] () [] []
    An array of Unicode characters that delimit the substrings in this instance, an empty array that contains no delimiters, or nullNothingnullptrunita null reference (Nothing in Visual Basic).

Return Value

Type: array<System. . :: . .String> [] () [] []
An array whose elements contain the substrings in this instance that are delimited by one or more characters in separator. For more information, see the Remarks section.

Remarks

Delimiter characters are not included in the elements of the returned array.

If this instance does not contain any of the characters in separator, the returned array consists of a single element that contains this instance. If count is zero, an empty array is returned.

If the separator parameter is null Nothing nullptr unit a null reference (Nothing in Visual Basic) or contains no characters, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and return true if they are passed to the Char.IsWhiteSpace method.

Each element of separator defines a separate delimiter character. If two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance, the corresponding array element contains Empty.

If there are more than count substrings in this instance, the first count minus 1 substrings are returned in the first count minus 1 elements of the return value, and the remaining characters in this instance are returned in the last element of the return value.

If count is greater than the number of substrings, the available substrings are returned and no exception is thrown.

The following table provides examples.

String value

Separator

Count

Returned array

"42, 12, 19"

new Char[] {',', ' '} (C#)

Char() = {","c, " "c} (Visual Basic)

2

{"42", " 12, 19"}

"42..12..19"

new Char[] {'.'} (C#)

Char() = {"."c} (Visual Basic)

4

{"42", "", "12", ".19"}

"Banana"

new Char[] {'.'} (C#)

Char() = {"."c} (Visual Basic)

2

{"Banana"}

"Darb\nSmarba" (C#)

"Darb" & vbLf & "Smarba" (Visual Basic)

new Char[] {} (C#)

Char() = {} (Visual Basic)

1

{"Darb\nSmarba"} (C#)

"Darb" & vbLf & "Smarba" (Visual Basic)

"Darb\nSmarba" (C#)

"Darb" & vbLf & "Smarba" (Visual Basic)

new Char[] null (C#)

Char() = Nothing

2

{"Darb", "Smarba"}

"Darb\nSmarba" (C#)

"Darb" & vbLf & "Smarba" (Visual Basic)

new Char[] null (C#)

Char() = Nothing

100

{"Darb", "Smarba"}

.NET Framework Security

See Also

Reference

String Class

Split Overload

System Namespace