String.Split Method (Char, StringSplitOptions)
Splits a string into substrings based on the characters in an array. You can specify whether the substrings include empty array elements.
Assembly: mscorlib (in mscorlib.dll)
[<ComVisibleAttribute(false)>] member Split : separator:char * options:StringSplitOptions -> string
A character array that delimits the substrings in this string, an empty array that contains no delimiters, or null.
Return ValueType: System.String
An array whose elements contain the substrings in this string that are delimited by one or more characters in separator. For more information, see the Remarks section.
Delimiter characters (the characters in the separator array) are not included in the elements of the returned array. For example, if the separator array includes the character "-" and the value of the current string instance is "aa-bb-cc", the method returns an array that contains three elements: "aa", "bb", and "cc".
If this instance does not contain any of the characters in separator, the returned array consists of a single element that contains this instance.
If the options parameter is RemoveEmptyEntries and the length of this instance is zero, the method returns an empty array.
Each element of separator defines a separate delimiter that consists of a single character. If the options argument is None, and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains String.Empty. For example, if separator includes two elements, "-" and "_", the value of the string instance is "-_aa-_", and the value of the options argument is None, the method returns a string array with the following five elements:
String.Empty, which represents the empty string that precedes the "-" character at index 0.
String.Empty, which represents the empty string between the "-" character at index 0 and the "_" character at index 1.
String.Empty, which represents the empty string that follows the "_" character at index 4.
String.Empty, which represents the empty string that follows the "-" character at index 5.
If the separator parameter is null or contains no characters, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and return true if they are passed to the Char.IsWhiteSpace method.
If the separator parameter in the call to this method overload is null, compiler overload resolution fails. To unambiguously identify the called method, your code must indicate the type of the null. The following example shows several ways to unambiguously identify this overload.
Themethod extracts the substrings in this string that are delimited by one or more of the characters in the separator parameter, and returns those substrings as elements of an array.
The Split method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the System.Globalization.CompareOptions enumeration.
TheSplit methods allocate memory for the returned array object and a String object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the IndexOf or IndexOfAny method, and optionally the Compare method, to locate a substring within a string.
If you are splitting a string at a separator character, use the IndexOf or IndexOfAny method to locate a separator character in the string. If you are splitting a string at a separator string, use the IndexOf or IndexOfAny method to locate the first character of the separator string. Then use the Compare method to determine whether the characters after that first character are equal to the remaining characters of the separator string.
In addition, if the same set of characters is used to split strings in multiple Split method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call.
Notes to Callers:
In the .NET Framework 3.5 and earlier versions, if the Split method is passed a separator that is null or contains no characters, the method uses a slightly different set of characters to split the string than the Trim method does to trim the string. In the .NET Framework 4, both methods use an identical set of Unicode white-space characters.
Available since 8
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1