C#_StringBuilder分离字符串实例

时间:2022-04-20 04:21: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(); } }
}