如何判断字符是否是Java中的字母? [英] How to determine whether a character is a letter in Java?

查看:199
本文介绍了如何判断字符是否是Java中的字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查一个字符的字符串是否是一个字母 - 包括带有重音的任何字母?

How do you check if a one-character String is a letter - including any letters with accents?

我最近必须解决这个问题,所以我会在最近的VB6问题提醒我之后,我自己回答。

I had to work this out recently, so I'll answer it myself, after the recent VB6 question reminded me.

推荐答案

只是检查一封信是否在AZ中,因为那不是包含带有重音符号或其他字母表中字母的字母。

Just checking if a letter is in A-Z because that doesn't include letters with accents or letters in other alphabets.

我发现你可以使用正则表达式类来表示Unicode字母或其区分大小写的变体之一:

I found out that you can use the regular expression class for 'Unicode letter', or one of its case-sensitive variations:

string.matches("\\p{L}"); // Unicode letter
string.matches("\\p{Lu}"); // Unicode upper-case letter

您也可以使用 Character 执行此操作class:

You can also do this with Character class:

Character.isLetter(character);

但如果您需要检查多个字母,则不太方便。

but that is less convenient if you need to check more than one letter.

这篇关于如何判断字符是否是Java中的字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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