width java,分析Java中的全宽或半宽字符

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

for example:

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

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

half width = t,e,s,t

full width = 思,題

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

Thanks a lot!

解决方案

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

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

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

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' ;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
和\r的区别以及它们在Java的使用。 在Java字符,"\n"和"\r"是两个不同的转义字符,用于表示换行符和回车符。"\n"表示换行符,其ASCII码是0x0A。当程序输出一个"\n"字符时,会使得光标移到下一行的开头位置。而"\r"表示回车符,其ASCII码是0x0D。当程序输出一个"\r"字符时,会使得光标移到当前行的开头位置,但不会换行,新输出的字符会覆盖掉当前行原有的内容。 需要注意的是,在Windows操作系统,回车符和换行符通常是成对出现的,即先输出一个"\r"字符,再输出一个"\n"字符,以实现在屏幕上的换行效果。而在Unix/Linux等操作系统,只需要输出一个"\n"字符即可实现换行。因此,要想在Java实现换行和回车的效果,可以使用"\n"或"\r\n"字符串,具体取决于所运行的操作系统。 综上所述,"\n"在Java字符表示换行符,"\r"表示回车符,它们的输出效果和使用方式与操作系统的相关性密切相关。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* *2* [在java\n和\r的区别](https://blog.csdn.net/qq_51980838/article/details/129988945)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值