NumberFormatException的解析印地文号时, [英] NumberFormatException when parsing Hindi numbers

查看:162
本文介绍了NumberFormatException的解析印地文号时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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);

这篇关于NumberFormatException的解析印地文号时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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