asp.net 如何精确获取汉字及其符号数量。。 在后台html编辑器中,添加文章内容后,如何在前台读取时精确的获取汉字及汉字符号啊。大部分情况下用程序截取字符串长度不够精确,因为里面还有html代码,有没有好的办法能精确的读取汉字及其符号啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Regex regex = new Regex("[\u4e00-\u9fa5]+", RegexOptions.Compiled);Reges.Replace("",@"[\u4e00-\u9fa5]+", ","")长度减 public static string NoHtml(string text) { //删除脚本 text = Regex.Replace(text, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); //删除HTML text = Regex.Replace(text, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"-->", "", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"<!--.*", "", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(amp|#38);", "&", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(lt|#60);", "<", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(gt|#62);", ">", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"&#(\d+);", "", RegexOptions.IgnoreCase); text.Replace("<", ""); text.Replace(">", ""); text.Replace("\r\n", ""); text = HttpContext.Current.Server.HtmlEncode(text).Trim(); return text; } 过滤掉html后计算 头疼问题,如何固定GridView模板列的宽度? c#后台添加超级链接 关于asp.net mvc asp.net ajax框架加载的JavaScript文件在什么地方? 求份JS效果代码 100 在asp.net中上传图片,怎样用C# 把gif和bmp格试转换为jpg格试 今天遇到一个很怪的问题? 关于asp.net 在线视频播放的问题 这个是怎么回事? 关于空参数的存储过程 DataList的问题 asp.net 发布问题 关于IIS的配置
Reges.Replace("",@"[\u4e00-\u9fa5]+", ","")
长度减
public static string NoHtml(string text)
{
//删除脚本
text = Regex.Replace(text, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
text = Regex.Replace(text, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"-->", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"<!--.*", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"&#(\d+);", "", RegexOptions.IgnoreCase); text.Replace("<", "");
text.Replace(">", "");
text.Replace("\r\n", ""); text = HttpContext.Current.Server.HtmlEncode(text).Trim();
return text;
} 过滤掉html后计算