待处理的字符串 /// 合并空格后的字符串 public static string MergeSpace(string">

C# 字符串中多个连续空格转为一个空格

来源:这里教程网 时间:2026-02-21 13:08:08 作者:

#region 字符串中多个连续空格转为一个空格
     /// <summary>
     /// 字符串中多个连续空格转为一个空格
     /// </summary>
     ///<param name="str">待处理的字符串
     /// <returns>合并空格后的字符串</returns>
     public static string MergeSpace(string str)
     {
         if (str != string.Empty &&
             str != null &&
             str.Length > 0
             )
         {
             str = new System.Text.RegularExpressions.Regex("[\s]+").Replace(str, " ");
         }
         return str;
     }
 
 
     #endregion

 以上就是c# 字符串中多个连续空格转为一个空格的内容,更多相关内容请关注php中文网(www.php.cn)!

相关推荐