当前位置: 编程技术>.net/c#/asp.net
asp.net正则表达式提取中文的代码示例
来源: 互联网 发布时间:2014-08-30
本文导语: 需求: 从一段字符串文本中获取所有中文字符。 核心代码,如下: //asp.net正则提取中文 //edit by www. public static string GetChineseWord(string oriText) { string x = @"[u4E00-u9FFF]+"; //正则 MatchCollection Matches = Regex.Matches(oriText, x, Regex...
需求:
从一段字符串文本中获取所有中文字符。
核心代码,如下:
//asp.net正则提取中文 //edit by www. public static string GetChineseWord(string oriText) { string x = @"[u4E00-u9FFF]+"; //正则 MatchCollection Matches = Regex.Matches(oriText, x, RegexOptions.IgnoreCase); StringBuilder sb = new StringBuilder(); foreach (Match NextMatch in Matches) { sb.Append(NextMatch.Value); } return sb.ToString(); }
代码说明:
注意以上正则表达式:[u4E00-u9FFF]+,即是匹配所有中文。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。