Click or drag to resize

RegexExtensionsSplitT Method

Splits an input string into an array of substrings at the positions defined by the regex regular expression.

Namespace:  TomsToolbox.Essentials
Assembly:  TomsToolbox.Essentials (in TomsToolbox.Essentials.dll)
Syntax
public static IEnumerable<T> Split<T>(
	this Regex regex,
	string input,
	Func<string, bool, T> itemGenerator
)

Parameters

regex
Type: System.Text.RegularExpressionsRegex
The regular expression used to split the string.
input
Type: SystemString
The string to split.
itemGenerator
Type: SystemFuncString, Boolean, T
The item generator used to generate the individual fragments to return. It will get the items string value plus a boolean indicator whether the item was a match or the text in between the matches.

Type Parameters

T
The type of the returned items.

Return Value

Type: IEnumerableT
The items generated by the itemGenerator, an alternating list of non-matched and matched fragments.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Regex. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks
Similar to Split(String), but returns and alternating list of both matches and non-matches. It's up to the item generator how matched and non-matched items are handled. Concatenating all unmodified fragment values will always return the original string.
See Also