如何判断字符是简体中文还是繁体中文及英文.

seikoo 2004-10-19 04:27:11
谢谢.高手快来....
...全文
1435 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaomineer 2004-10-21
  • 打赏
  • 举报
回复
如果是用unicode编码,那么能否判断上面我发的那个unicode标准的FAQ已经说得很明白。那就是不能判断,因为这里面有很多例外,如果非要判断结果也是不准确的。

如果是gb2312或者big5编码,那么可以将其转化成内码,但是他们的内码范围是重叠的。正如: jamesfancy()边城狂人(James Fancy) 所指出的那样。因此按照你的程序,根据内码判断,结果只能判断出一部分繁体。或者说结果是不准确的。

最后我也觉得这种判断是没有必要的,如果想转化就直接转好了。
seikoo 2004-10-20
  • 打赏
  • 举报
回复
public class Charset {

public static boolean isCS(String str){
if(null==str) return false;
if(str.trim()=="") return false;
byte[] bytes=str.getBytes();
if(bytes.length<2)
return false;
byte aa=(byte)0xB0;
byte bb=(byte)0xF7;
byte cc=(byte)0xA1;
byte dd=(byte)0xFE;
if(bytes[0]>=aa && bytes[0]<=bb){
if(bytes[1]<cc || bytes[1] > dd){
return false;
}
return true;
}
return false;
}
public static boolean isBig5(String str){
if(null==str) return false;
if(str.trim()=="") return false;
byte[] bytes=str.getBytes();
if(bytes.length<2)
return false;
byte aa=(byte)0xB0;
byte bb=(byte)0xF7;
byte cc=(byte)0xA1;
byte dd=(byte)0xFE;
if(bytes[0]>=aa && bytes[0]<=bb){
if(bytes[1]<cc || bytes[1] > dd){
return true;
}
return false;
}
return false;
}
}
自己来吧.
xiaomineer 2004-10-20
  • 打赏
  • 举报
回复
Q: How can I recognize from the 32 bit value of a Unicode character if this is a Chinese, Korean or Japanese character?

A: It's basically impossible and largely meaningless. It's the equivalent of asking if "a" is an English letter or a French one. There are *some* characters where one can guess based on the source information in Unihan.txt that it's traditional Chinese, simplified Chinese, Japanese, Korean, or Vietnamese, but there are too many exceptions to make this really reliable. (For example, one particularly nasty obscenity in Cantonese would probably have never been encoded for Cantonese, but has made it in for the sake of Korean, where one hopes it isn't nearly as obscene.)

The phonetic data in Unihan.txt should not be used for this purpose. A blank in the phonetic data means that nobody's supplied a reading, not that a reading doesn't exist. Because updating the Unihan database is an ongoing process, these fields will be increasingly filled out as time goes on, but they should never be taken as absolutely complete. In particular, there are obscure characters where it is known that there *is* a reading, but since the character does not occur in standard dictionaries, we are unable to supply it (e.g., U+40DF in Cantonese).

A better solution is to look at the text as a whole: if there's a fair amount of kana, it's probably Japanese, and if there's a fair amount of hangul, it's probably Korean.

The only proper mechanism is, as for determining whether "chat" is spelled correctly in English or French, is to use a higher-level protocol
seikoo 2004-10-20
  • 打赏
  • 举报
回复
好像是有点问题...能够处理判断一部分的繁体...
xiaomineer 2004-10-20
  • 打赏
  • 举报
回复
seikoo(上下求索)
我不清楚你的程序是怎么考虑的,但是我copy了你的程序然后在我的机器上执行,
结果是我输入繁体中文的时候用isBig5判断返回false.
边城狂人 2004-10-19
  • 打赏
  • 举报
回复
看看字节码范围

GB2312

字节 1: 0xA1-0xFE
字节 2: 0xA1-0xFE

分 94 个区,每个区 94 个字

BIG5

字节 1: 0xA1-0xF9
字节 2: 0x40-0x7E 和 0xA1-0xFE

分 89 个区,每个区 157 个字


如果是GBK中的敏体字,在 0x40-0xa1之间,可以看出来,编码是有重复的,所以,实在不好判断哪些是简体,哪些是繁体。
seikoo 2004-10-19
  • 打赏
  • 举报
回复
那简体和繁体呢?
winterxu416 2004-10-19
  • 打赏
  • 举报
回复
在JavaScript中:/[^\x00-\xff]/ig.test(str) 返回true表示你的str中含有中文字符
在Java中也一样的使用这个正则表达式,就可以测试出是否含有中文字符啦.
课程目标:学习Java语言中字符串相关的知识、字符编码常识和正则表达式的使用,并完成案例前导课程:《Java工程师必学系列课程》前4部课程内容:本课程是《Java工程师必学系列课程》的第5部分,主要讲解Java语言中字符串相关知识、字符编码常识和正则表达式的使用。本课程涉及的主要内容可以分为四部分:一、String、StringBuffer和StringBuilder类基本常识、基本原理和使用技巧二、字符编码常识三、Java语言正则表达式的详细语法和使用技巧四、实战案例课程说明:在开发Java程序的过程中,最常用的类莫过于字符串相关的类。可以毫不夸张的说,任何一个Java程序,都离不开对字符串保存和处理。很多学员对字符串的理解只是处于比较粗浅的阶段。殊不知,如果对字符串处理的不好,会影响到软件的运行效率。本课程专门讲解字符串相关的知识,将从字符串的存储方式、底层的运行方式等各方面深入讲解其中的原理和技巧。此外,对字符串进行更高级的处理,又要用到正则表达式的相关知识。正则表达式广泛应用于各种与字符串处理相关的场合。它是一套独立的语言系统,经过几十年的完善和发展,现在已经非常的强大,并且形成了国际标准。各种高级编程语言,都实现了自己的表达式引擎。本课程详细的讲解了Java语言中正则表达式的语法和使用技巧。掌握了正则表达式,对编程水平的提高有非常大的帮助!同时,本课程在最后一部分,安排了非常精彩的、完整的实战案例,通过实战的形式切实帮助学员提高解决具体问题的能力!预期效果:认真学习完本课程,学员可以掌握字符串处理及正则表达式相关的系统知识,并能提高实际的编码水平。环境配置要求:学习本课程需安装JDK1.8或更高版本的JDK,以便程序能正确运行,建议使用IntelliJ IDEA 2019.1.2或更高版本的开发工具。    因有合作协议约束,《穆哥学堂》只提供PDF版本的课件!

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧