C#如何去掉字符串中所有空格

作者在 2010-12-12 09:44:04 发布以下内容
由于空格的ASCII码值是32,因此,在去掉字符串中所有的空格时,只需循环访问字符串中的所有字符,并判断它们的ASCII码值是不是32即可。去掉字符串中所有空格的关键代码如下:
  CharEnumeratorCEnumerator=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();
  }
  }

默认分类 | 阅读 963 次
文章评论,共0条
游客请输入验证码
浏览2893次
文章分类
最新评论