检查分组分隔符是否为空格 [英] Check if a grouping separator is a space

查看:185
本文介绍了检查分组分隔符是否为空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检查一个分组分隔符( char )是否是一个空格。这是法语区域设置的情况,但我的测试总是打印 false

I am trying to check wether a grouping separator (char) is a space or not. It's the case for the french locale but my test always prints false.

DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(Locale.forLanguageTag("fr"));
char ch = formatter.getDecimalFormatSymbols().getGroupingSeparator();
System.out.println(ch == ' '); // false
System.out.println(Character.isWhitespace(ch)); // false


推荐答案

接收的unicode符号不是正常空格。这是一个不间断空格。您的字符具有 160 不是 32 的整数表示形式。
要检查是否应该使用:

The unicode symbol you receive is not a normal whitespace. It's a no-break space. Your char has the integer representation of 160 not 32. To check that you should use:

Character.isSpaceChar(ch);

该方法根据unicode标准检查字符是否为空格。



以下方法根据Java规范检查charactre是否为空格。

That method checks if a character is a space according to the unicode standard.

The following method checks if a charactre is a space according to Java specification.

Character.isWhitespace(ch);

有关标准的详细说明,请参阅文档。

A detailed description of the criteria can be found at the documentations.

这篇关于检查分组分隔符是否为空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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