C#如何过滤连续相同的字符串?

其中,\s 表示空格,{1,} 表示连续1个以上的空格,RegexOptions.IgnoreCase 表示不区分大小写。

public static class StringHelper {
    public static string ReplaceSeriesString(string str) {
        var replaced = new Regex(@"\s{1,}", RegexOptions.IgnoreCase);
        return replaced.Replace(str, " ").Trim();
    }
}
  

 

posted @ 2021-02-20 16:20  imnet  阅读(368)  评论(0)    收藏  举报