Java中的Character.isAlphabetic和Character.isLetter有什么区别? [英] What is the difference between Character.isAlphabetic and Character.isLetter in Java?

查看:3656
本文介绍了Java中的Character.isAlphabetic和Character.isLetter有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java中的Character.isAlphabetic()和Character.isLetter()有什么区别?什么时候应该使用一个?何时应该使用另一个?

What is the difference between Character.isAlphabetic() and Character.isLetter() in Java? When should one use one and when should one use the other?

推荐答案

根据API docs ,如果角色具有以下任何一般类别类型,isLetter()将返回true:UPPERCASE_LETTER(Lu ),LOWERCASE_LETTER(Ll),TITLECASE_LETTER(Lt),MODIFIER_LETTER(Lm),OTHER_LETTER(Lo)。如果我们比较isAlphabetic(),它有相同但添加LETTER_NUMBER(Nl),以及任何具有Other_Alphabetic属性的字符。

According to the API docs, isLetter() returns true if the character has any of the following general category types: UPPERCASE_LETTER (Lu), LOWERCASE_LETTER (Ll), TITLECASE_LETTER (Lt), MODIFIER_LETTER (Lm), OTHER_LETTER (Lo). If we compare isAlphabetic(), it has the same but adds LETTER_NUMBER (Nl), and also any characters having Other_Alphabetic property.

这在实践中意味着什么?每个字母都是字母,但不是每个字母都是字母 - 在Java 7(使用Unicode 6.0.0)中,BMP中有824个字符,它们是字母而不是字母。一些例子包括0345(一个用于多音希腊语的组合器),从05B0开始的希伯来元音点(niqqud),在0610的阿拉伯敬语,如锯(和平在他身上),阿拉伯语元音点...列表继续。

What does this mean in practice? Every letter is alphabetic, but not every alphabetic is a letter - in Java 7 (which uses Unicode 6.0.0), there are 824 characters in the BMP which are alphabetic but not letters. Some examples include 0345 (a combiner used in polytonic Greek), Hebrew vowel points (niqqud) starting at 05B0, Arabic honorifics such as saw ("peace be upon him") at 0610, Arabic vowel points... the list goes on.

但基本上,对于英文文本,区别没有区别。对于其他一些语言而言,区别可能会有所不同,但很难预先预测实际差异。如果有一个选择,最好的答案可能是isLetter() - 将来可以改变以允许其他字符,但减少接受字符集可能会更难。

But basically, for English text, the distinction makes no difference. For some other languages, the distinction might make a difference, but it is hard to predict in advance what the difference might be in practice. If one has a choice, the best answer may be isLetter() - one can always change to permit additional characters in the future, but reducing the set of accepted characters might be harder.

这篇关于Java中的Character.isAlphabetic和Character.isLetter有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆