Export (0) Print
Expand All

Regex.Split Method (String, Int32, Int32)

Splits the specified input string a specified maximum number of times at the positions defined by a regular expression specified in the Regex constructor, starting at a specified character position in the input string

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

public string[] Split (
	string input,
	int count,
	int startat
)
public String[] Split (
	String input, 
	int count, 
	int startat
)
public function Split (
	input : String, 
	count : int, 
	startat : int
) : String[]

Parameters

input

The string to be split.

count

The maximum number of array elements to return.

startat

The character position in the input string where the search will begin.

Return Value

An array of strings.

The Regex.Split methods are similar to the Split method, except this method splits the string at a delimiter determined by a regular expression instead of a set of characters. If count is specified, the string is split into at most count strings (the last string containing the unsplit remainder of the string); a count value of zero provides the default behavior of splitting as many times as possible. If startat is specified, the first delimiter is searched for starting at the specified point (this can be used, for example, for skipping leading white space).

Also, if capturing groups are used in a split expression, these are included in the array of split strings. For example:

 Regex r = new Regex("(-)"); // Split on hyphens.
 string[] s = r.Split("one-two-banana");

would yield the following array items:"one", "-", "two", "-", "banana"

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

The static Split methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Split. The static methods are provided to allow an isolated, single use of a regular expression without explicitly creating a Regex object.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft