C# String Split(Char[])
Description
String Split(Char[])
returns a string array that contains
the substrings in this instance that are delimited by elements of a specified
Unicode character array.
Syntax
String.Split(Char[])
has the following syntax.
public string[] Split(
params char[] separator
)
Parameters
String.Split(Char[])
has the following parameters.
separator
- An array of Unicode characters that delimit the substrings in this instance, an empty array that contains no delimiters, or null.
Returns
String.Split(Char[])
method returns
Example
The following example demonstrates how to extract individual words from a block of text by treating white space and punctuation marks as delimiters.
using System;//from w ww. ja v a 2 s .c o m
public class SplitTest {
public static void Main() {
string words = "This is a test\tand a tab character.";
string [] split = words.Split(new Char [] {' ', ',', '.', ':', '\t' });
foreach (string s in split) {
if (s.Trim() != "")
Console.WriteLine(s);
}
}
}
The code above generates the following result.