[英]Java scanner useDelimiter doesn't work in French
I've got a string of floating point numbers like 我有一串浮点数,例如
1.0000\0.0000\0.0000\0.00000\1.0000\0.0000\0.0000
which I need to parse. 我需要解析。 I use the Java Scanner using the backslash as the delimiter.
我使用Java扫描程序,将反斜杠用作分隔符。 It has been working for years in English.
它已经用英语工作了多年。 Just today I put on French as the default language and in French it fails to parse, ie it doesn't find the next double.
就在今天,我将法语作为默认语言,并且用法语无法解析,即找不到下一个双精度型。 I also have Hebrew on the computer and it parses in Hebrew with no problem.
我在计算机上也安装了希伯来语,并且可以使用希伯来语进行解析。 Just French is a problem.
只是法语是个问题。
Here is the code: 这是代码:
static float[] parseMultFloat( String tmp1) {
float [] ret1 = null;
double[] val = new double[32]; // arbitrary limit of 32
int i, n = 0;
if( tmp1 == null) return null;
Scanner sc = new Scanner(tmp1).useDelimiter("\\\\");
while(sc.hasNextDouble() && n < 32) {
val[n++] = sc.nextDouble();
}
if( n>0) {
ret1 = new float[n];
for( i=0; i<n; i++) ret1[i] = (float) val[i];
}
return ret1;
}
With the debugger I can single step up to the while(sc.hasNextDouble)
. 使用调试器,我可以单步执行
while(sc.hasNextDouble)
。 In English and Hebrew it will find all my numbers. 用英语和希伯来语,它将找到我的所有电话号码。 In French it just jumps over the while and leaves
n=0
. 在法语中,它仅跳过一会儿并留下
n=0
。
Is there any other way to get my numbers, which will also work in French? 还有什么其他方法可以获取我的电话号码,该方法也适用于法语?
Scanner is locale aware. 扫描仪知道区域设置。 For French a double would look like 0,00023
对于法国人来说,双数看起来像是0,00023
Set the US locale before reading the next double, if the format does not change. 如果格式不变,请在读取下一个双精度值之前设置美国语言环境。
sc.useLocale(Locale.US);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.