C# String Split(Char[], StringSplitOptions)
Description
String Split(Char[], StringSplitOptions)
returns
a string array that contains the substrings in this string that are delimited
by elements of a specified Unicode character array. A parameter specifies
whether to return empty array elements.
Syntax
String.Split(Char[], StringSplitOptions)
has the following syntax.
[ComVisibleAttribute(false)]/* w w w. j a v a 2s. com*/
public string[] Split(
char[] separator,
StringSplitOptions options
)
Parameters
String.Split(Char[], StringSplitOptions)
has the following parameters.
separator
- An array of Unicode characters that delimit the substrings in this string, an empty array that contains no delimiters, or null.options
- RemoveEmptyEntries to omit empty array elements from the array returned; or None to include empty array elements in the array returned.
Returns
String.Split(Char[], StringSplitOptions)
method returns
Example
This example demonstrates the String() methods that use the StringSplitOptions enumeration.
using System;/*from w w w . j a va2 s . c om*/
class Sample
{
public static void Main()
{
string s1 = ",ONE,,TWO,,,THREE,,";
char[] charSeparators = new char[] {','};
string[] stringSeparators = new string[] {"[stop]"};
string[] result;
result = s1.Split(charSeparators, StringSplitOptions.None);
Show(result);
}
public static void Show(string[] entries){
foreach (string entry in entries){
Console.WriteLine(entry);
}
}
}
The code above generates the following result.