<笔记>如何分割string

来源:互联网 发布:流固耦合软件 编辑:程序博客网 时间:2024/06/09 17:24
class TestStringSplit{    static void Main()    {        char[] delimiterChars = { ' ', ',', '.', ':', '\t' };        string text = "a\tb c:d,e f g";        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:    a    b    c    d    e    f    g */

As input, Split takes an array of chars that indicate which characters are to be used as delimiters.
原创粉丝点击