c#中的字符串多个空格合并为一个空格的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cdc8596/article/details/86534955

#region 字符串中多个连续空格转为一个空格 
/// <summary> 
/// 字符串中多个连续空格转为一个空格 
/// </summary> 
/// <param name="str">待处理的字符串</param> 
/// <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

猜你喜欢

转载自blog.csdn.net/cdc8596/article/details/86534955