c# String字符串相关

Posted wxstar8

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# String字符串相关相关的知识,希望对你有一定的参考价值。

1、分割字符串并去除为空的的内容。

      StreamReader sr = new StreamReader(“C:/test.txt”, Encoding.Default)

      string[] strCodes = sr.ReadLine().Split( new string[]",",StringSplitOptions.RemoveEmptyEntries);//用“,”分割字符串并去除为空的项,使用:StringSplitOptions.RemoveEmptyEntries  属性。


2、将数组转换为字符串,在每项后面添加一个特定的字符。

    List<string> strBits = new List<string>();

    strBits.add("wang");

    strBits.add("Li");

    strBits.add("Sun");

    string Names = string.Join(",", strBits.ToArray());//在每项后面添加一个“,”号

       

以上是关于c# String字符串相关的主要内容,如果未能解决你的问题,请参考以下文章