unicode编码、字符的转换和得到汉字的区位码
一:unicode编码、字符的转换截图

二:unicode编码、字符的转换代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace ASCII
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
} private void btn_ToASCII_Click(object sender, EventArgs e)
{
if (txt_char.Text != string.Empty)//判断输入是否为空
{
if (Encoding.GetEncoding("unicode").//判断输入是否为字母,数字,标点符号,等
GetBytes(new char[] { txt_char.Text[] })[] == )//编码的第1位为0
{
txt_ASCII.Text = Encoding.GetEncoding(//得到字符的ASCII码值
"unicode").GetBytes(txt_char.Text)[].ToString();
MessageBox.Show(txt_char.Text[].ToString());
}
else
{
txt_ASCII.Text = string.Empty;//输出空字符串
MessageBox.Show("请输入字母!","提示!");//提示用户信息
}
}
}
private void btn_ToChar_Click(object sender, EventArgs e)
{
if (txt_ASCII2.Text != string.Empty)//判断输入是否为空
{
int P_int_Num;//定义整型局部变量
if (int.TryParse(//将输入的字符转换为数字
txt_ASCII2.Text, out P_int_Num))
{
txt_Char2.Text =
((char)P_int_Num).ToString();//将ASCII码转换为字符
}
else
{
MessageBox.Show(//如果输入不符合要求弹出提示框
"请输入正确ASCII码值。", "错误!");
}
}
string P_str_temp = "abc";
string P_str = Encoding.GetEncoding("unicode").GetBytes(new char[] { P_str_temp[] })[].ToString();
}
}
}
三:得到汉字的区位码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace ChineseCode
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
} private void btn_Get_Click(object sender, EventArgs e)
{
if (txt_Chinese.Text != string.Empty)//判断输入是否为空
{
try
{
txt_Num.Text = //得到汉字区位码信息
getCode(txt_Chinese.Text);
}
catch (IndexOutOfRangeException ex)
{
MessageBox.Show(//使用消息对话框提示异常信息
ex.Message + "请输入正确的汉字", "出错!");
}
}
}
/// <summary>
/// 得到汉字区位码方法
/// </summary>
/// <param name="strChinese">汉字字符</param>
/// <returns>返回汉字区位码</returns>
public string getCode(string Chinese)
{//(' 区位码是与汉字一一对应的编码,用四位数字表示,
//前两位从01 到94称区码,后两位从01到94称位码。 一个汉字的前一半是 ASCⅡ码为“160+区码”的字符,
//后一半是ASCⅡ码为“160+ 位码”的字符。'例如:“刘”的区位码是 3385,
//其意为区码33位码85,它是由ASCⅡ码为160+33=193和160+85=245的两个字符组成。 byte[] P_bt_array = Encoding.Default.GetBytes(Chinese);//得到汉字的Byte数组
int front = (short)(P_bt_array[] - '\0');//将字节数组的第一位转换成short类型,这里(short)code[0]也是可以的
int back = (short)(P_bt_array[] - '\0');//将字节数组的第二位转换成short类型
return (front - ).ToString() + (back - ).ToString();//计算并返回区位码
}
}
}
unicode编码、字符的转换和得到汉字的区位码的更多相关文章
- Unicode编码解码在线转换工具
		
// Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...
 - javascript实现unicode与字符互相转换
		
javascript实现unicode与字符互相转换. <script language="javascript"> //手机检测 function checkMo ...
 - Unicode编码下字符串转换
		
VC\MFC当中CString.string.char.char*.char数组.int等类型之间的转换令人晕头转向,特地搜集多篇文章资料,利用代码实例等清晰的理清他们之间的关系和如何转换,其实非常简 ...
 - utf8、ansii、unicode编码之间的转换
		
#include "stdafx.h"#include "windows.h"#include <iostream>#include <str ...
 - 由Unicode编码想到弄懂编码表
		
test unicode好 007400650073007400200075006E00690063006F00640065597D 这是一个Unicode编码,一共六七万的汉字,可以说Unicode ...
 - ASCII&UNICODE编码演化
		
ASCII 上个世纪60年代,美国制定了基于拉丁字母的一套电脑编码系统,取名为ASCII.它主要用于显示现代英语和其他西欧语言,是现今最通用的单字节编码系统. ASCII码使用指定的7位或8位二进制数 ...
 - windows程序设计 Unicode和多字节之间转换
		
Unicode转多字节:WideCharToMultiByte 多字节转Unicode:MultiByteToWideChar 代码演示 #include <windows.h> int ...
 - C#怎么判断字符是不是汉字 汉字和Unicode编码互相转换
		
判断一个字符是不是汉字通常有三种方法,第1种用 ASCII 码判断(在 ASCII码表中,英文的范围是0-127,而汉字则是大于127,根据这个范围可以判断),第2种用汉字的 UNICODE 编码范围 ...
 - .Net(c#)汉字和Unicode编码互相转换
		
{"Tilte": "\u535a\u5ba2\u56ed", "Href": "http://www.cnblogs.com&q ...
 
随机推荐
- Mongodb 启动时 lock文件访问没有权限处理
			
mongodb 第二次启动时候异常信息: lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance ...
 - decimal to hexadecimal,binary and octonary.
			
Here is a simple algorithm about 'decimal' to 'dexadecimal',and the implementation code: /* Convert ...
 - java simple check whether a file or directory.
			
Ref: check whether a file or directory First, make sure the path exists by using: new File(path).ex ...
 - 最终版-perl工具解析数据库的报告文件0120
			
********************需要根据自己的实际环境修改哦**************************** ******************** 1. 收集awr报告样本 a ...
 - vs里 .sln和.suo 文件
			
Net解决方案下 .sln文件和.suo文件的解释:When a Web site is created, a solution file (.sln) and a hidden solution u ...
 - Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)
			
方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...
 - 【转】《我的WCF之旅》博文系列汇总
			
转自:http://www.cnblogs.com/artech/archive/2007/09/15/893838.html WCF是构建和运行互联系统的一系列技术的总称,它是建立在Web Serv ...
 - javascript——面向对象程序设计(1)
			
<script type="text/javascript"> //ECMA-262把对象定义为:“无序属性的 集合,其属性可以包含基本值.对象或者函数” //理解对象 ...
 - 响应式十日谈第一日:使用 rem 设置文字大小
			
上面回顾: 在序言中我们已经提到了响应式的一些基本理念,比如: 响应式网页不仅仅是响应不同类型的设备,而且需要响应不同的用户需求.响应式的初衷是为了让信息更好的传递交流,让所有人无障碍的获取信息,同时 ...
 - Django socketio 安装
			
如果你还没有安装过 gevent,首先需要安装 libevent, 编译安装 libevent 需要安装 Pyhton 开发库. 在Debain上可以运行如下指令: $ sudo apt-get in ...