首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#除了字符串空格的方法

2012-12-20 
C#去除字符串空格的方法?//方法一,使用正则表达式:/*zfc是输入或要检测的字符串。*/System.Text.RegularExp

C#去除字符串空格的方法

?

//方法一,使用正则表达式:/*zfc是输入或要检测的字符串。*/System.Text.RegularExpressions.Regex.Replace(zfc, "([ ]+)", "");//方法一,使用字符串自带的Replace方法:zfc.Replace(" ","");//方法三:根据空格的ASCII码值是32,所以对每个字符进行判断,如果ASCII值是32则说明是空格:CharEnumerator CEnumerator = textBox1.Text.GetEnumerator(); while (CEnumerator.MoveNext()) {        byte[] array = new byte[1];        array = System.Text.Encoding.ASCII.GetBytes(CEnumerator.Current.ToString());        int asciicode = (short)(array[0]);        if (asciicode != 32)        {               textBox2.Text += CEnumerator.Current.ToString();        } } //这里的3种方法只能去除半角空格,不能去除全角空格

?参见:http://blog.csdn.net/qotima/archive/2008/09/26/2983554.aspx

热点排行