国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

emoji表情與unicode編碼互轉的實現(JS,JAVA,C#)

瀏覽:20日期:2022-08-18 17:47:37

前幾天剛好有需求要把emoji對應的Unicode編碼轉換成文字,比如1f601對應的這個笑臉😁,但沒有找到C#的把1f601轉換成文字的方法,用Encoding.Unicode怎么轉換都不對,最后直接復制emoji字符,Visual Studio里面竟然直接顯示出來了,那就直接用字符吧,都不用轉換了,然后不了了之了。

今天搞Markdown編輯器,由于前面GFM的原因,又對編碼進行測試,沒查到什么靠譜資料,到時找到很多emoji和Unicode對照表,https://apps.timwhitlock.info/emoji/tables/unicode拿一個笑臉https://apps.timwhitlock.info/unicode/inspect/hex/1F601開刀~

1.表情字符轉編碼

【C#】

Encoding.UTF32.GetBytes('😁') -> ['1', 'f6', '1', '0']

【js】

'😁'.codePointAt(0).toString(16) -> 1f601

【java】

byte[] bytes = '😀'.getBytes('utf-32'); System.out.println(getBytesCode(bytes)); private static String getBytesCode(byte[] bytes) { String code = ''; for (byte b : bytes) { code += 'x' + Integer.toHexString(b & 0xff); } return code; }

UTF-32結果一致

【C#】

Encoding.UTF8.GetBytes('😁') -> ['f0', '9f', '98', '81']

【js】

encodeURIComponent('😁') -> %F0%9F%98%81

UTF-8結果一致

2.編碼轉表情字符

【js】

String.fromCodePoint(’0x1f601’) utf-32

【java】

String emojiName = '1f601'; //其實4個字節 int emojiCode = Integer.valueOf(emojiName, 16); byte[] emojiBytes = int2bytes(emojiCode); String emojiChar = new String(emojiBytes, 'utf-32'); System.out.println(emojiChar); public static byte[] int2bytes(int num){ byte[] result = new byte[4]; result[0] = (byte)((num >>> 24) & 0xff);//說明一 result[1] = (byte)((num >>> 16)& 0xff ); result[2] = (byte)((num >>> 8) & 0xff ); result[3] = (byte)((num >>> 0) & 0xff ); return result; }c# 漢字和Unicode編碼互相轉換實例

/// <summary>/// <summary>/// 字符串轉Unicode/// </summary>/// <param name='source'>源字符串</param>/// <returns>Unicode編碼后的字符串</returns>public static string String2Unicode(string source){ byte[] bytes = Encoding.Unicode.GetBytes(source); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < bytes.Length; i += 2) { stringBuilder.AppendFormat('u{0}{1}', bytes[i + 1].ToString('x').PadLeft(2, ’0’), bytes[i].ToString('x').PadLeft(2, ’0’)); } return stringBuilder.ToString();} /// <summary>/// Unicode轉字符串/// </summary>/// <param name='source'>經過Unicode編碼的字符串</param>/// <returns>正常字符串</returns>public static string Unicode2String(string source){ return new Regex(@'u([0-9A-F]{4})', RegexOptions.IgnoreCase | RegexOptions.Compiled).Replace( source, x => string.Empty + Convert.ToChar(Convert.ToUInt16(x.Result('$1'), 16)));}參考地址:

https://www.jianshu.com/p/8a416537deb3

https://blog.csdn.net/a19881029/article/details/13511729

https://apps.timwhitlock.info/emoji/tables/unicode

到此這篇關于emoji表情與unicode編碼互轉的實現(JS,JAVA,C#)的文章就介紹到這了,更多相關emoji表情與unicode編碼互轉內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Java
相關文章:
主站蜘蛛池模板: 欧产日产国产精品精品 | 国产日本亚洲欧美 | 国产精品日韩欧美一区二区 | 成人在线手机视频 | 亚洲情a成黄在线观看 | 纯欧美一级毛片免费 | 成人性视频在线三级 | 欧美午夜a级精美理论片 | 久久精品成人免费网站 | 欧美亚洲另类视频 | 亚洲精品一二三区-久久 | 免费观看欧美精品成人毛片 | 色偷偷亚洲偷自拍 | 天天看片天天爽 | www.黄色大片| 亚洲三级网址 | 精品无码三级在线观看视频 | 91欧美激情一区二区三区成人 | 午夜欧美成人 | 成人伊人青草久久综合网 | 毛片精品 | 久草免费在线观看视频 | 国产精品成人一区二区 | 成人免费视频日本 | 精品视频一区二区三区 | 成人毛片免费观看视频在线 | 成人国产永久福利看片 | 国产精品视频网址 | 久久亚洲不卡一区二区 | 国内精品一区二区三区最新 | 交videos人妖| 一级片久久 | 夜夜躁狠狠躁日日躁2021 | 久久99精品久久久久久秒播 | 免费观看成为人视频 | 国产综合精品久久久久成人影 | 欧美变态一级毛片 | 精品韩国主播福利视频在线观看一 | 亚洲三级黄色片 | 国产综合精品久久久久成人影 | 波多野结衣在线观看高清免费资源 |