我正在尝试将字符串解析为Integer。我正在从excel文件中读取此字符串。
String nos=new String((sheet.getCell(1, i).getContents().replace(" NOS", ""))).trim().replaceAll("^ *", "");
int stock=Integer.parseInt(nos);下面是错误java.lang.NumberFormatException: For input string: """827"""
发布于 2014-11-17 13:34:42
您可以使用像"\"*(\\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)));
}输出为
827https://stackoverflow.com/questions/26966108
复制相似问题