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());//在每项后面添加一个“,”号
扫描二维码关注公众号,回复:
1743772 查看本文章