C#Split

之前做一个例子,没有做出来,虽然知道是用Split。今天遇到一个例子,记下来

string s="a b      dfg_   +   =   ,,,,  ffda   ";
//分割字符串Split
char[] chs ={' ','_','+','=',','};

string []str=s.Split(chs,StringSplitOptions.RemoveEmptyEntries);
Console.ReadKey();

这样,第二个参数StringSplitOptions是一个枚举

另外,string.Join()方法

string[] names={"张三""李四""王五""赵六""田七"};
//想要的字符串: 张三|李四|王五|赵六|田七
string strNew=string.Join("|",names);
Console.WriteLine(strNew);
Console.ReadKey();

 

原文地址:https://www.cnblogs.com/jellydong/p/6947178.html