C#_StringBuilder分离字符串实例

来源:互联网 发布:逻辑回归模型 知乎 编辑:程序博客网 时间:2024/05/22 14:09
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace StringBuilderTest{    class Program    {        static void Main(string[] args)        {            string s1 = "one,two,three library,INC.";            const char Space = ' ';            const char Comma = ',';            char[] delimiters = new char[]            {            Space,            Comma            };            StringBuilder output = new StringBuilder();            int ctr = 1;            foreach (string subString in s1.Split(delimiters))            {                output.AppendFormat("{0}: {1} \n",ctr++,subString);            }            Console.WriteLine(output);            Console.ReadLine();        }    }}