Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java NumberFormatException_Java_Jxl - Fatal编程技术网

Java NumberFormatException

Java NumberFormatException,java,jxl,Java,Jxl,我正在尝试将字符串解析为整数。我正在从excel文件中读取此字符串 String nos=new String((sheet.getCell(1, i).getContents().replace(" NOS", ""))).trim().replaceAll("^ *", ""); int stock=Integer.parseInt(nos); 以下是错误java.lang.NumberFormatException:对于输入字符串:“827”您可以使用类似“\”*

我正在尝试将字符串解析为整数。我正在从excel文件中读取此字符串

String nos=new String((sheet.getCell(1, i).getContents().replace(" NOS", ""))).trim().replaceAll("^ *", "");
            int stock=Integer.parseInt(nos);

以下是错误
java.lang.NumberFormatException:对于输入字符串:“827”

您可以使用类似
“\”*(\\d+\“**”
的正则表达式,它可以选择匹配数字周围的引号和后面的任何内容。通过使用括号,我们对数字进行分组,然后我们可以像

String str = "\"\"827\"\" NOS";
Pattern p = Pattern.compile("\"*(\\d+)\"*.*");
Matcher m = p.matcher(str);
if (m.matches()) {
    System.out.println(Integer.parseInt(m.group(1)));
}
输出为

827
添加另一个
.replaceAll(“\”,”)