本文介绍了检测Java中的任何组合字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来检测java字符串中的字符是否是组合字符。例如,

I am looking for a way to detect if a character in a java string "is a combining character" or not. For instance,

String khmerCombiningVowel = 
 new String(new byte[]{(byte) 0xe1,(byte) 0x9f,(byte) 0x80}, "UTF-8"); // unicode 17c0

表示。我试过\\\\ {InCombiningDiacriticalMarks} ,是一些用于组合字符的块。

According to Algorithm to check for combining characters in Unicode, there are a number of blocks for combining characters.

Java有许多有用的功能,请尝试:

Java has a number of helpful functions, try:

String codePointStr = new String(new byte[]{(byte) 0xe1, (byte) 0x9f, (byte) 0x80}, "UTF-8"); // unicode 17c0
System.out.println(codePointStr.matches("\\p{Mc}"));
System.out.println(
    Character.COMBINING_SPACING_MARK == Character.getType(codePointStr.codePointAt(0)));

(在两种情况下都打印为真)

(prints true in both cases)

在这种情况下,Mark,Spacing Combining,它基本上是任何与前一个字符组合的字符,同时还会增加宽度。

In this case, the COMBINING_SPACING_MARK (and related regex \p{gc=Mc}) both refer to the Unicode category "Mark, Spacing Combining" which is basically any character that combines with a previous character while also adding width.

其他可能有用的正则表达式:<$ h $ => http://www.regular-expressions \p {M} .info / unicode.htmlrel =nofollow noreferrer>任何类型的标记。如果要使用Character getType()常量,可以通过检查其类型是否为 COMBINING_SPACING_MARK ENCLOSING_MARK ,或 NON_SPACING_MARK

Other regular expressions that may be useful: \p{M} for any kind of mark. If you want to use the Character getType() constants, you can get the same behavior to that by checking if its type is COMBINING_SPACING_MARK or ENCLOSING_MARK, or NON_SPACING_MARK.

ENCLOSING_MARK是一个周围的角色,就像一个圆圈 - 也为它结合的角色增加了宽度。

ENCLOSING_MARK is a surrounding character, like a circle--also adds width to the character it combines with.

包括拉丁字母变音组合标记等(标记基本上位于顶部或以下,并且不要为角色添加任何宽度。)

NON_SPACING_MARK includes the Latin alphabet diacritical combining marks, etc. (Marks that basically go on top or below, and don't add any width to the character).

这篇关于检测Java中的任何组合字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 18:02