public string[] Split(params char[] seperator)
separator 的每一个元素都定义一个单独的分隔符字符。如果两个分隔符相邻,或者在此实例的开头或末尾找到分隔符,则相对应的数组元素包含 Empty。
| "42, 19, 52" |
new char[] {',' , ''} |
{"42","","19","","52"} |
| "42,,19,,52" |
new char[]{','} |
{"42","","19","","52"} |
| "42..19..52" |
new char[]{','} |
{"42..19..52"} |
public static void Main() {
string words = "This is a list of words, with: a bit of punctuation.";
string [] split = words.Split(new Char [] {' ', ',', '.', ':'});
foreach (string s in split) {
if (s.Trim() != "")
Console.WriteLine(s);
}
}
}
// The example displays the following output to the console:
// This
// is
// a
// list
// of
// words
// with
// a
// bit
// of
// punctuation