string类的GetCharEnumerator方法去掉字符串中空格
2012-01-17 00:03
176 查看
像之前一样为了自己更好的理解,多次输出中间值,把每个字符的ASCII码都输出了。
GetCharEnumerator方法能够循环访问字符串中的每一个字符,然后用current属性获得当前字符。
呃,我记住了空格的ASCIIi码是32。
string strRead=Console.ReadLine();
string strWrite = string.Empty;
CharEnumerator xh = strRead.GetEnumerator();
while (xh.MoveNext())
{
byte[] asciicode = System.Text.Encoding.ASCII.GetBytes(xh.Current.ToString());
if (asciicode[0] != 32)
{
Console.Write(asciicode[0] + " ");
strWrite += xh.Current.ToString();
}
else
{
Console.Write(asciicode[0] + " ");
}
}
Console.Write("\n"+strWrite);
Console.ReadLine();
GetCharEnumerator方法能够循环访问字符串中的每一个字符,然后用current属性获得当前字符。
呃,我记住了空格的ASCIIi码是32。
string strRead=Console.ReadLine();
string strWrite = string.Empty;
CharEnumerator xh = strRead.GetEnumerator();
while (xh.MoveNext())
{
byte[] asciicode = System.Text.Encoding.ASCII.GetBytes(xh.Current.ToString());
if (asciicode[0] != 32)
{
Console.Write(asciicode[0] + " ");
strWrite += xh.Current.ToString();
}
else
{
Console.Write(asciicode[0] + " ");
}
}
Console.Write("\n"+strWrite);
Console.ReadLine();
相关文章推荐
- JavaScript去掉字符串两边空格的方法
- c#中去掉字符串空格方法
- Python去掉字符串中空格的方法
- js去掉字符串前后空格的五种方法
- 去掉字符串中間空格的方法
- python去掉字符串中空格的方法
- c#中去掉字符串空格方法
- 去掉字符串连续多个空格的方法
- c#中去掉字符串空格方法
- jQuery去掉字符串起始和结尾的空格(多种方法实现)
- Python去掉字符串中空格的方法
- 20141014个人日志(ios 字符串轻易去掉空格的方法)
- js去掉字符串前后空格的五种方法
- js去掉字符串前后空格的五种方法
- jQuery去掉字符串起始和结尾的空格(多种方法实现)
- 在objective-c中去掉字符串前后空格的方法
- objective-C 中类似于C#中trim的方法(去掉字符串前后空格)
- c#去掉字符串空格的的方法
- js去掉字符串前后空格的五种方法(转)
- Python去掉字符串中空格的方法