分析Java中的全宽或半宽字符 [英] Analyzing full width or half width character in Java

查看:445
本文介绍了分析Java中的全宽或半宽字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分析char数组中的全宽或半宽字符。

I would like to analyze full width or half width character in char array.

例如:

char [] password = {'t','e','s','t','思','题'};

char [] password = {'t','e','s','t','思','題'};

已满此char数组中的宽度和半宽字符。

There are full width and half width characters in this char array.

half width = t,e,s,t

half width = t,e,s,t

full width =思,题

full width = 思,題

那么,如何分析java中char数组的全宽或半宽?

So, how can I analyze full width or half width for char array in java?

非常感谢!

推荐答案

JDK包含一个提及完整/半宽的类: InputSubset

JDK contains one class that mentions full/half width: InputSubset

http://docs.oracle.com/javase/7/docs/api/java/awt/im/InputSubset.html

不幸的是,没有办法检查哪个字符落在哪个子集中。

Unfortunately there's no method to check which char falls in which subset.

尽管如此,显然全/半宽是一个定义明确的unicodes概念。互联网上可能存在准确的规范。

Nonetheless, apparently full/half width is a well defined concept for unicodes. There maybe an accurate spec somewhere on internet.

http ://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms

http://en.wikipedia.org/wiki/DBCS

我想这对你的用例来说已经足够了要说的是,0x00-0xFF字符是半宽的;其他字符是全宽的,除了unicode块中的半宽字符Halfwidth and Fullwidth Forms

I guess it'll be good enough for your use case to say that, 0x00-0xFF chars are half-width; other chars are full-width, except the half-width chars in the unicode block "Halfwidth and Fullwidth Forms"

boolean isHalfWidth(char c)
{
    return '\u0000' <= c && c <= '\u00FF'
        || '\uFF61' <= c && c <= '\uFFDC'
        || '\uFFE8' <= c && c <= '\uFFEE' ;
}

这篇关于分析Java中的全宽或半宽字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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