與技巧0093對應的是,根據區位碼獲得其對應的漢字時,需要使用System.Text.Encoding類中Default編碼方式的GetString方法對給出的區位碼進行編碼。獲得區位碼對應漢字的關鍵代碼如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
byte[] array = new byte[2];
string str = textBox1.Text.Trim();
string str1 = str.Substring(0, 2);
string str2 = str.Substring(2, 2);
int front = Convert.ToInt32(str1) + 160;
int back = Convert.ToInt32(str2) + 160;
array[0] = (byte)front;
array[1] = (byte)back;
textBox2.Text = System.Text.Encoding.Default.GetString(array);
}
}
}