C#删除字符串中所有的空字符
1 string sourceStr = "Hi, Bo ys "; 2 char[] pChar = sourceStr.ToCharArray();//转换成字符数组 3 IEnumerator p = pChar.GetEnumerator();//得到IEnumerator 对象 4 StringBuilder sbBuilder = new StringBuilder(); 5 while (p.MoveNext())//调用IEnumerator 对象的MoveNext方法 6 { 7 sbBuilder.Append((char) p.Current != ' ' ? p.Current.ToString() : String.Empty); 8 }