String.Split 方法 (Char[])使用示例
public string[] Split( params char[] separator )
下面的示例演示如何通过将空白和标点符号视为分隔符来提取文本块中的各个单词。
using System;
public class SplitTest {
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