由于空格的ASCII码值是32,因此,在去掉字符串中所有的空格时,只需循环访问字符串中的所有字符,并判断它们的ASCII码值是不是32即可。去掉字符串中所有空格的关键代码如下:

testCharEnumeratorCEnumerator=textBox1.Text.GetEnumerator();
while(CEnumerator.MoveNext())
{
  byte[]array=newbyte[1];
  array=System.Text.Encoding.ASCII.GetBytes(CEnumerator.Current.ToString());
  intasciicode=(short)(array[0]);
  if(asciicode!=32)
  {
    textBox2.Text+=CEnumerator.Current.ToString();
  }
}



作者:水木