更新:2007 年 11 月
下面的代码示例演示如何使用
示例
C# | 复制代码 |
---|---|
class TestStringSplit { static void Main() { char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; string text = "one\ttwo three:four,five six seven"; System.Console.WriteLine("Original text: '{0}'", text); string[] words = text.Split(delimiterChars); System.Console.WriteLine("{0} words in text:", words.Length); foreach (string s in words) { System.Console.WriteLine(s); } // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); } } /* Output: Original text: 'one two three:four,five six seven' 7 words in text: one two three four five six seven */ |