天天看點

C# 将字元串中的多個連續空格變成一個

public static string MergeSpace(string str)
        {
            if (!string.IsNullOrEmpty(str))
            {
                str = new System.Text.RegularExpressions.Regex("[\\s]+").Replace(str, " ");
            }
            return str;
        }