asp.net.ph

String.Split Method ( Char [ ], Int32 )

System Namespace   String Class


Identifies the substrings in the given String 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.

[ VB ]
<Serializable>
Overloads Public Function Split ( _
   ByVal separator ( ) As Char, _
   ByVal count As Integer _
) As String ( )

[ C# ]
[ Serializable ]
public string [ ] Split (
   char [ ] separator,
   int count
);

[ C++ ]
[ Serializable ]
public: String* Split (
   __wchar_t separator __gc [ ],
   int count
) __gc [ ];

[ JScript ]
public Serializable
function Split (
   separator : Char [ ],
   count : int
) : String [ ];

Parameters

separator
An array of Unicode characters that delimit the substrings in the given String, an empty array containing no delimiters, or a null reference ( Nothing in Visual Basic ).
count
The maximum number of array elements to return.

Return Value

An array consisting of a single element containing this instance, if this instance contains none of the characters in separator.

-or-

An array of substrings if this instance is delimited by one or more of the characters in separator.

-or-

An array of the substrings in the given String delimited by white space characters if those characters occur and separator is a null reference ( Nothing in Visual Basic ) or contains no delimiter characters.

Empty is returned for any substring where two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance.

Delimiter characters are not included in the substrings.

Exceptions


Exception Type Condition
ArgumentOutOfRangeException count is negative.

Remarks

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

For example:

Input separator, count Output
"42, 12, 19" new Char [ ] {',', ' '}, 2 {"42", " 12, 19"}
"42..12..19" new Char [ ] {'.'},4 {"42", "", "12", ".19"}
"Banana" new Char [ ] {'.'},2 {"Banana"}
"Darb\nSmarba" new Char [ ] {}, 1 {"Darb\nSmarba"}
"Darb\nSmarba" new Char [ ] null,2 {"Darb", "Smarba"}
"Darb\nSmarba" new Char [ ] null,100 {"Darb", "Smarba"}

See Also

String Members   String.Split Overload List   Char   Array   Int32   Concat   Insert   Join   Remove   Replace   Substring   Trim Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph