当前位置: 编程技术>.net/c#/asp.net
c#中文gbk编码查询(示例)
来源: 互联网 发布时间:2014-08-30
本文导语: 例子,c#中文gbk编码查询示例。 代码示例: private void button_Inquriy_Click(object sender, EventArgs e) { if (textBox_Inquiry.TextLength > 0) { String strInquiry = textBox_Inquiry.Text; byte[] bytes = Encoding.GetEncoding...
例子,c#中文gbk编码查询示例。
代码示例:
private void button_Inquriy_Click(object sender, EventArgs e)
{
if (textBox_Inquiry.TextLength > 0)
{
String strInquiry = textBox_Inquiry.Text;
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(strInquiry); //gbk中文编码查询
String strResult = String.Empty;
foreach (byte b in bytes)
{
strResult += b.ToString("X2");
strResult += " ";
}
textBox_Result.Text = strResult;
}
else
{
MessageBox.Show("请输入待查询的字符");
}
}
{
if (textBox_Inquiry.TextLength > 0)
{
String strInquiry = textBox_Inquiry.Text;
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(strInquiry); //gbk中文编码查询
String strResult = String.Empty;
foreach (byte b in bytes)
{
strResult += b.ToString("X2");
strResult += " ";
}
textBox_Result.Text = strResult;
}
else
{
MessageBox.Show("请输入待查询的字符");
}
}