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


static void Main()
{
//demo1 除去空格,提取出各个单词
string s = "a b c";
string[] word = s.Split(new char[] { ' ' });
foreach (string temp in word)
Console.WriteLine(temp);

//demo2 直接去除所有空格
s=s.Replace(" ","");
Console.WriteLine(s);

//demo3 去掉首尾空格
s = " aaa ";
s = s.Trim();
Console.WriteLine(s);
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM