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.
Assembly: System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)
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, 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 exception is thrown if the execution time of the split operation exceeds the time-out interval specified by the 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 , no exception is thrown
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.