1、漢字轉(zhuǎn)十六進(jìn)制UNICODE編碼字符串
/// <summary> /// //// /// </summary> /// <param name="character"></param> /// <returns></returns> public string CharacterToCoding(string character) { string coding = ""; for (int i = 0; i < character.Length; i++) { byte[] bytes = System.Text.Encoding.Unicode.GetBytes(character.Substring(i, 1)); //取出二進(jìn)制編碼內(nèi)容 string lowCode = System.Convert.ToString(bytes[0], 16); //取出低字節(jié)編碼內(nèi)容(兩位16進(jìn)制) if (lowCode.Length == 1) { lowCode = "0" + lowCode; } string hightCode = System.Convert.ToString(bytes[1], 16); //取出高字節(jié)編碼內(nèi)容(兩位16進(jìn)制) if (hightCode.Length == 1) { hightCode = "0" + hightCode; } coding += (hightCode + lowCode); } return coding; }
2、 十六進(jìn)制UNICODE編碼字符串 轉(zhuǎn) 漢字
/// <summary> /// // /// </summary> /// <param name="text"></param> /// <returns></returns> public string UnicodeToCharacter(string text) { byte[] arr = HexStringToByteArray(text); System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); string str = converter.GetString(arr); return str; }
以上這篇c# 實(shí)現(xiàn)獲取漢字十六進(jìn)制Unicode編碼字符串的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答