去除两端空格,其他空格替换成一个空格

string msg = " hello word,你 好 世界 ! ";
msg = msg.Trim();
string[] w = msg.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
string full = string.Join(" ",w);
Console.WriteLine(full);
Console.ReadKey();

posted @ 2024-03-22 13:20  過朢  阅读(20)  评论(0)    收藏  举报