您好,登錄后才能下訂單哦!
這篇文章主要介紹“C#怎么制作unicode到gb2312映射表”,在日常操作中,相信很多人在C#怎么制作unicode到gb2312映射表問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”C#怎么制作unicode到gb2312映射表”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } class unit_converter : IComparable<unit_converter> { public int gb2312 = 0; public int unicode = 0; public unit_converter() { } public unit_converter(int gb2312_0, int gb2312_1) { init_with_gb2312(gb2312_0, gb2312_1); } private int CompareWithUnicode(unit_converter other) { return unicode.CompareTo(other.unicode); } private int CompareWithGB2312(unit_converter other) { return gb2312.CompareTo(other.gb2312); } public int CompareTo(unit_converter other) { if(unicode == other.unicode) { Console.WriteLine("something wrong with gb2312: "+ gb2312.ToString("X4") + "unicode: "+unicode.ToString("X4")); } return CompareWithUnicode(other); //return CompareWithGB2312(other); } private byte[] _gb2312 = new byte[2]; private byte[] _unicode = new byte[2]; public void init_with_gb2312(int gb2312_0, int gb2312_1) { _gb2312[0] = (byte)gb2312_0; _gb2312[1] = (byte)gb2312_1; gb2312 = _gb2312[0] * 256 + _gb2312[1]; String s_target_gb2312 = System.Text.Encoding.GetEncoding("GB2312").GetString(_gb2312); byte[] b_target_unicode = System.Text.Encoding.GetEncoding("unicode").GetBytes(s_target_gb2312); _unicode[0] = b_target_unicode[1]; _unicode[1] = b_target_unicode[0]; unicode = _unicode[0] * 256 + _unicode[1]; } private void init_with_unicode(int unicode_0, int unicode_1) { _unicode[0] = (byte)unicode_1; _unicode[1] = (byte)unicode_0; unicode = _unicode[0] * 256 + _unicode[1]; String s_target_unicode = System.Text.Encoding.GetEncoding("unicode").GetString(_unicode); byte[] b_target_gb2312 = System.Text.Encoding.GetEncoding("GB2312").GetBytes(s_target_unicode); _gb2312[0] = b_target_gb2312[0]; _gb2312[1] = b_target_gb2312[1]; gb2312 = _gb2312[0] * 256 + _gb2312[1]; } } List<unit_converter> elements = new List<unit_converter>(); private void make_src_gb2312() { for (int index_level_1 = 0xA1; index_level_1 < 0xAA; index_level_1++) { for (int index_level_2 = 0xA1; index_level_2 < 0xFF; index_level_2++) { elements.Add(new unit_converter(index_level_1, index_level_2)); } } for (int index_level_1 = 0xB0; index_level_1 < 0xF7; index_level_1++) { for (int index_level_2 = 0xA1; index_level_2 <= 0xFF; index_level_2++) { elements.Add(new unit_converter(index_level_1, index_level_2)); } } Console.WriteLine("CNT " + elements.Count.ToString()); elements.Sort(); } private String save_to_string() { String target_string = ""; target_string += "uint16_t const sorted_unicode[MAX_UNI_INDEX] = {"; int length = elements.Count(); for(int i =0; i < length; i++) { if(i%8 == 0) { target_string += "\r\n "; } target_string += " 0x" + elements[i].unicode.ToString("X4") + ","; } target_string += "\r\n};"; target_string += "\r\nuint16_t const sorted_gb2312[MAX_UNI_INDEX] = {"; for (int i = 0; i < length; i++) { if (i % 8 == 0) { target_string += "\r\n "; } target_string += " 0x" + elements[i].gb2312.ToString("X4") + ","; } target_string += "\r\n};"; return target_string; } private void save_to_file() { String t = save_to_string(); } private void font_test() { } private void Form1_Load(object sender, EventArgs e) { //C9AD 森 byte[] b_src_gb2312 = new byte[2] { 0xC9, 0xAD }; byte[] b_src_unicode = new byte[2] { 0x02, 0x30 }; unit_converter converter = new unit_converter(b_src_gb2312[0], b_src_gb2312[1]); //String s_target_gb2312 = System.Text.Encoding.GetEncoding("GB2312").GetString(b_src_gb2312); //byte[] b_target_unicode = System.Text.Encoding.GetEncoding("unicode").GetBytes(s_target_gb2312); //String s_target_unicode = System.Text.Encoding.GetEncoding("unicode").GetString(b_target_unicode); String s_target_unicode = System.Text.Encoding.GetEncoding("unicode").GetString(b_src_unicode); byte[] b_target_gb2312 = System.Text.Encoding.GetEncoding("GB2312").GetBytes(s_target_unicode); make_src_gb2312(); save_to_file(); font_test(); Console.WriteLine("start"); } } }
到此,關(guān)于“C#怎么制作unicode到gb2312映射表”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。