Split Method (String)

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

Splits an input string into an array of substrings at the positions defined by a regular expression pattern specified in the Regex constructor.

Namespace:  System.Text.RegularExpressions
Assembly:  System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)

array<String^>^ Split(
	String^ s


Type: System..::..String
The string to split.

Return Value

Type: array<System..::..String>[]()[][]
An array of strings.

The Regex..::..Split methods are similar to the String..::..Split(array<Char>[]()[][]) method, except that Regex..::..Split splits the string at a delimiter determined by a regular expression instead of a set of characters. The string is split as many times as possible. If no delimiter is found, the return value contains one element whose value is the original input string.

If multiple matches are adjacent to one another, an empty string is inserted into the array. For example, splitting a string on a single hyphen causes the returned array to include an empty string in the position where two adjacent hyphens are found.

If a match is found at the beginning or the end of the input string, an empty string is included at the beginning or the end of the returned array. The following example uses the regular expression pattern \d+ to split an input string on numeric characters. Because the string begins and ends with matching numeric characters, the value of the first and last element of the returned array is String..::..Empty.

If capturing parentheses are used in a Regex..::..Split expression, any captured text is included in the resulting string array. For example, if you split the string "plum-pear" on a hyphen placed within capturing parentheses, the returned array includes a string element that contains the hyphen.

If the regular expression can match the empty string, Split(String) will split the string into an array of single-character strings because the empty string delimiter can be found at every location.

Note that the returned array also includes an empty string at the beginning and end of the array.

The RegexMatchTimeoutException exception is thrown if the execution time of the split operation exceeds the time-out interval specified by the Regex.#ctor(String, RegexOptions, TimeSpan) constructor. If you do not set a time-out interval when you call the constructor, the exception is thrown if the operation exceeds any time-out value established for the application domain in which the Regex object is created. If no time-out is defined in the Regex constructor call or in the application domain's properties, or if the time-out value is Regex.InfiniteMatchTimeout, no exception is thrown