BBS水木清华站∶精华区
发信人: intranetworm (小虫), 信区: Java
标 题: Unicode 汉字与GB内码的转换
发信站: BBS 水木清华站 (Wed Aug 27 13:44:45 1997)
这是我编的一个转换程序,使用时现将前面的码表存成文件,例如table.txt
创建一个GBUnicode实例,new GBUnicode("table.txt")
以后调用GB2Uni和Uni2GB作内码转换.注意GB内码是用两个字节表示的.
import java.io.*;
import java.util.Hashtable;
class GBUnicode{
byte high[]=new byte[6763],low[]=new byte[6763];
char unichar[]=new char[6763];
Hashtable UniGB;
public GBUnicode(String table_file)throws IOException
{
//BufferedInputStream tables=new BufferedInputStream (new FileInputStream(table_file));
DataInputStream tables=new DataInputStream (new FileInputStream(table_file));
int i,n=0;
byte b,bl,bh,num[]=new byte[20];
UniGB=new Hashtable(7000,1);
while (n<6763 ){
do{
bh=(byte)tables.read();
}while ((char)bh<=' '); //find first non-blank char
bl=(byte)tables.read();
high[n]=bh;
low[n]=bl;
do{
b=(byte)tables.read();
}while (b!=(byte)':'); //find ':'
do{
b=(byte)tables.read();
}while ((char)b<=' '); //find next non-blank char to read as number
i=0;
while ((char)b>='0' && (char)b<='9'){
num[i++]=b;
b=(byte)tables.read();
}
unichar[n]=(char)Integer.parseInt(new String(num,0,0,i));
if (UniGB.get(new Character(unichar[n]))!= null)
System.out.println("Duplicated : "+unichar[n]);
UniGB.put(new Character(unichar[n]),new Integer(n));
n=n+1;
}
tables.close();
}
private int getGBindex(byte high,byte low){
int i,j;
i=high-(byte)0xb0;
j=low-(byte)0xa1;
if (i <39) {// L1 Chinese
if (j<0 || j>94)
return -1;
return (i*94+j);
}
else if (i==39) {//one of the last 89 L1 Chinese
if (j<0 || j>89)
return -1;
return (i*94+j);
}
else {//L2 Chinese
if (j<0 || j>94)
return -1;
return (i*94+j-5);
}
}
public byte[] Uni2GB(char unicode) {
Integer index=(Integer)UniGB.get(new Character(unicode));
if (index==null)
return null;
byte ch[]=new byte[2];
ch[0]=high[index.intValue()];
ch[1]=low[index.intValue()];
return ch;
}
public char GB2Uni(byte high, byte low) {
int index=getGBindex(high,low);
if (index ==-1) //not GB Chinese
return 0;
return(unichar[index]);
}
}
--
※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: organ.ncic.ac.c]
BBS水木清华站∶精华区
分享到:
相关推荐
Unicode汉字内码表对照,很齐全的对照
通用规范汉字UNICODE码表,提供一级字表、二级字表、三级字表全部8105字的UNICODE编码
最全的常用汉字Unicode码表,举例:\u7684\u4e00\u662f\u4e86\u6211\u4e0d\u4eba\u5728\u4ed6\u6709\u8fd9\u4e2a\u4e0a\u4eec\u6765\u5230\u65f6\u5927\u5730\u4e3a\u5b50\u4e2d\u4f60\u8bf4\u751f\u56fd\u5e74 。
unicode汉字和拼音对照表,按照: 汉字 编码 拼音声标 拼音声调(声调在字母后)声调在拼音后 纯拼音 的格式排列。一共是20902个汉字编码范围是 U4e00 ~ U9fa5.
常用的中文Unicode码表,作为开发人员必备的码表。希望对大家有帮助!
汉字 拼音 首字母 unicode码 对照 ,附带说明
这是常用汉字的Unicode码表,和传智播客视频中的一致,谢谢大家分享
通过查表实现C语言GBK、Unicode与UTF8互转,含转码表及接口函数,用于处理汉字编码的转码
包括《Unicode汉字编码表(hex).txt》、《汉字拼音对照表2.TXT》、《Unicode汉字内码表(十进制).txt》
汉字一、二级字库的汉字与unicode编码(十六进制)对照表,按照unicode的顺序排列
UNICODE GBK 编码转换表 用与裸机已经嵌入式开发中UNICODE支持
【unicode汉字编码表】,列分别是:汉字,全拼,五笔,郑码,UNICODE,GBK,笔画数,部首,笔顺编号,没有多音字的对照,如有错误请评论反馈,以便进行更正,谢谢
该文档适合于网页制作的开发人员或初学者,文档里面包括了常用汉字的unicode编码,可以很方便的帮助大家。希望大家多多采用!
完整的Unicode码表 包括汉字、英文、藏文、泰米尔、日韩等各国语言编码。
UTF8,UINCODE GBK码表,介绍了中文字符部分的区别 , 帮助开发指导使用
GB18030是正式国家标准,是GBK或GB2312的超集。...这里是一个Excle版本的码表,罗列出码元及对应的GBK编码和Unicode编码,是研究编码的好工具. 部分字体可能显示不出来,请尝试更换字体,或者安装包含字符较多的字体再尝试
这是网友海峰多年来收集整理的五笔和笔画编码表,涵盖了UNICODE国际通用字符集规定的全部汉字。 SunWb_MB.xls工作薄中包含7个表,内容分别是GB三重简码表、GBK集、CJK扩展A集、CJK扩展B集、CJK兼容与扩充集、特殊...
很全面的日文码表。 例: 【儛】[JIS第4水準] SJIS: ── Unicode: 511B [用例] 岩手県一関市舞川 字 大平 儛草神社(まいくさじんじゃ・神社名称)
当需要对一个unicode十六进制字符串进行编码时,首先做的应该是确认字符集编码格式,在无法快速获知的情况下,通过一下的str4all方法可以达到这一目的