如何删除字符串中的空字符?
比如字符串string str="A","B","C","","F","","J"
如何把C后面的那个空字符串删掉?
也就是最后的字符串是"A","B","C","F","","J"
[解决办法]
void Main(){ string str="ABC F J"; Regex reg=new Regex("\\s+"); str=reg.Replace(str,"",1); Console.WriteLine(str); //ABCF J}
[解决办法]
str=str.Remove(3,1);
[解决办法]
string str="A,B,C,,F,J"; string[] s = str.Split(','); IList list = new ArrayList(); for (int i = 0; i < s.Length; i++) { if (s[i]!="") { list.Add(s[i]); } } for (int k = 0; k < list.Count; k++) { Response.Write(list[k] + ","); }