日期:2014-05-18  浏览次数:20514 次

如何删除字符串中的空字符?
比如字符串string str="A","B","C","","F","","J"
如何把C后面的那个空字符串删掉?

也就是最后的字符串是"A","B","C","F","","J"


------解决方案--------------------
C# code

void Main()
{
    string str="ABC F J";
    Regex reg=new  Regex("\\s+");
    str=reg.Replace(str,"",1);
    Console.WriteLine(str);  //ABCF J
}

------解决方案--------------------
C# code

str=str.Remove(3,1);

------解决方案--------------------
C# code

 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] + ",");

            }