using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Szmedi.RevitToolkit.Approval.Extensions { internal static class Extension { /// /// 提取字符串中所有中文字符 /// public static string ExtractChinese(this string text) { if (string.IsNullOrEmpty(text)) return string.Empty; // 先将非中文替换为空格,再将连续空格替换为单个空格,最后去除首尾空格 var result = Regex.Replace(text, @"[^\u4e00-\u9fa5]", " "); result = Regex.Replace(result, @"\s+", " ").Trim(); return result; } } }