之前做一个例子,没有做出来,虽然知道是用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();

 C#Split

 

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2021-11-14
  • 2022-12-23
  • 2021-07-02
  • 2021-11-24
猜你喜欢
  • 2021-12-14
  • 2021-10-03
  • 2021-07-25
  • 2021-12-16
  • 2022-02-07
  • 2022-01-07
  • 2022-01-31
相关资源
相似解决方案