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"}
 下面的示例演示如何通过将空白和标点符号视为分隔符来提取文本块中的各个单词。传递给 String..::.Split(array<Char>[]()[]) 方法的 separator 参数的字符数组包含空白字符和一些常用标点符号。

 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

相关文章: