Home  >  Article  >  Backend Development  >  Convert multiple consecutive spaces in a C# string to one space

Convert multiple consecutive spaces in a C# string to one space

黄舟
黄舟Original
2016-12-27 13:53:331418browse

#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)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn