NumberFormatException的解析印地文号时,文号、印地、NumberFormatException

由网友(宇宙猛男、)分享简介:我有一个Android应用程序,今天我有它包含了崩溃报告:I have an android application and today I have got a crash report which contains this:这当应用程序试图解析这是由用户提供的串号异常触发。This exception trig...

我有一个Android应用程序,今天我有它包含了崩溃报告:

I have an android application and today I have got a crash report which contains this:

这当应用程序试图解析这是由用户提供的串号异常触发。

This exception trigger when the application tries to parse string number which is provided by the user.

很明显,问题是应用程序无法分析印地文数字!所以,我怎么能解决这个?

It is obvious that problem is the application cannot parse Hindi numbers! So, how can I solve this?

推荐答案

使用正则表达式会更好,如果你想匹配任何C单$ C $ digits.The正则表达式将 p {N} + 这里是如何使用它:

Regex

Using regex would be better if you want to match any unicode digits.The regex would be p{N}+ and here's how to use it:

Matcher m=Pattern.compile("p{N}+").matcher(input);
if(m.find())
{
    System.out.println(m.group());
}

区域设置

要回答你的问题,你应该使用的NumberFormat 中所提到的文档。指定 区域设置 $为 的NumberFormat

Locale

佳文赏析 地理学报 胡焕庸的地缘战略思想及其时代价值

To answer your question you should use NumberFormat as mentioned in docs. Specify a Locale for NumberFormat.

NumberFormat nf = NumberFormat.getInstance(new Locale("hi", "IN"));
nf.parse(input);