zoukankan      html  css  js  c++  java
  • net core 导出内容带微信表情emoji 后乱码问题


    #region [解决微信表情emoji] /// <summary> /// 过滤emoji 或者 其他非文字类型的字符 /// </summary> /// <param name="source">param source</param> /// <returns></returns> public static String filterEmoji(String source) { if (string.IsNullOrWhiteSpace(source)) { return ""; } source = source.Replace("[^\\u0000-\\uFFFF]", "").Replace("??", ""); if (!containsEmoji(source)) { return source; //如果不包含,直接返回 } //到这里铁定包含 StringBuilder buf = null; int len = source.Length; for (int i = 0; i < len; i++) { char codePoint = source[i]; if (!isEmojiCharacter(codePoint)) { if (buf == null) { buf = new StringBuilder(source.Length); } buf.Append(codePoint); } else { } } if (buf == null) { return source; //如果没有找到 emoji表情,则返回源字符串 } else { if (buf.Length == len) { //这里的意义在于尽可能少的toString,因为会重新生成字符串 buf = null; return source; } else { return buf.ToString(); } } } /// <summary> /// 检测是否有emoji字符 /// </summary> /// <param name="source"></param> /// <returns></returns> public static bool containsEmoji(String source) { if (string.IsNullOrEmpty(source)) { return false; } int len = source.Length; for (int i = 0; i < len; i++) { char codePoint = source[i]; if (isEmojiCharacter(codePoint)) { //do nothing,判断到了这里表明,确认有表情字符 return true; } } return false; } /// <summary> /// 去掉表情符号 /// </summary> /// <param name="codePoint"></param> /// <returns></returns> public static bool isEmojiCharacter(char codePoint) { return (codePoint >= 0x2600 && codePoint <= 0x27BF) // 杂项符号与符号字体 || codePoint == 0x303D || codePoint == 0x2049 || codePoint == 0x203C || (codePoint >= 0x2000 && codePoint <= 0x200F) // || (codePoint >= 0x2028 && codePoint <= 0x202F) // || codePoint == 0x205F // || (codePoint >= 0x2065 && codePoint <= 0x206F) // /* 标点符号占用区域 */ || (codePoint >= 0x2100 && codePoint <= 0x214F) // 字母符号 || (codePoint >= 0x2300 && codePoint <= 0x23FF) // 各种技术符号 || (codePoint >= 0x2B00 && codePoint <= 0x2BFF) // 箭头A || (codePoint >= 0x2900 && codePoint <= 0x297F) // 箭头B || (codePoint >= 0x3200 && codePoint <= 0x32FF) // 中文符号 || (codePoint >= 0xD800 && codePoint <= 0xDFFF) // 高低位替代符保留区域 || (codePoint >= 0xE000 && codePoint <= 0xF8FF) // 私有保留区域 || (codePoint >= 0xFE00 && codePoint <= 0xFE0F) // 变异选择器 // || (codePoint >= U + 2600 && codePoint <= 0xFE0F) || codePoint >= 0x10000; // Plane在第二平面以上的,char都不可以存,全部都转 } #endregion

    来源:https://www.cnblogs.com/lilo202/p/8058012.html

      

  • 相关阅读:
    Delphi 2010下安装IOComp
    为自定义控件的某个属性添加像Winform控件中属性的注释
    C#WinForm仿qq窗体拖到windows窗体边上时,自动隐藏C#WinForm
    给图片添加水印,解决GIF添加水印的问题(无法从带有索引像素格式的图像创建 Graphics 对象)
    怎样把Image数据放入数据库
    取消IE“已限制此网页运行可以访问计算机的脚本
    sql 二进制文件的导入导出
    [转载]数据结构笔试题基础
    [转载]搜索算法(含基本搜索算法与深度搜索与广度搜索算法等思想)
    [转载]面试笔试总结
  • 原文地址:https://www.cnblogs.com/shiyilang398/p/15691428.html
Copyright © 2011-2022 走看看