将字符串 “ hello word,你 好 世 界 ! ” 两端空格去掉并且将其中的其他所有空格替换成一个空格 输出结果为“hello word,你 好 世界”

string str = "     hello      word,你 好 世  界  !     ";
            string msg = str.Trim();  //去掉首尾空格
            //使用split分割字符串,stringSplitOptions枚举去掉空格返回字符串数组类型
            string[] s = msg.Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries);
            //for (int i = 0; i < s.Length; i++)
            //{
            //    Console.WriteLine(s[i]);
            //}
            //在使用字符串join连接参数,它string数据s 用空格连接起来
           string m= string.Join(" ", s);
            Console.WriteLine(m);
            Console.ReadKey();