Java 忽略引号之间的字符
我从一个文件中有几个类似的字符串,我的代码告诉它用逗号分割每一行,如果一行是作者,输出它,如果它是标题输出它,e.t.c.如标签所示,2号打印输出,但1号只打印标题和日志,我基本上认为这是因为中间的字符,这是我分割的代码,我如何告诉它忽略中间的字符或替换它们Java 忽略引号之间的字符,java,Java,我从一个文件中有几个类似的字符串,我的代码告诉它用逗号分割每一行,如果一行是作者,输出它,如果它是标题输出它,e.t.c.如标签所示,2号打印输出,但1号只打印标题和日志,我基本上认为这是因为中间的字符,这是我分割的代码,我如何告诉它忽略中间的字符或替换它们 1. @Article{Balogh:2015:OBW, author = "J{\'a}nos Balogh and J{\'o}zsef B{\'e}k{\'e}si and Gy{\"
1. @Article{Balogh:2015:OBW,
author = "J{\'a}nos Balogh and J{\'o}zsef B{\'e}k{\'e}si and
Gy{\"o}rgy D{\'o}sa and Leah Epstein and Hans Kellerer
and Asaf Levin and Zsolt Tuza",
title = "Offline black and white bin packing",
journal = {Theor. Comput. Sci.}
}
2.@Article{DAngelo:2015:MSP,
author = "Gianlorenzo D'Angelo and Daniele Diodati and Alfredo
Navarra and Cristina M. Pinotti",
title = "The minimum $k$-storage problem on directed graphs",
journal = {Theor. Comput. Sci.}
}
分裂的代码
printArray = InArray[i].trim().split( ",(?=([^\"]*\"[^\"]*\")*(?![^\"]*\"))" ,-1);
我试过这个
printArray = InArray[i].trim().split(",");
这个
但是我不断地得到索引越界异常我这样做基本上是为了解决这个问题
printArray = InArray[i].replaceAll("\\\\\"", "").trim().split(",(?=([^\"]*\"[^\"]*\")*(?![^\"]*\"))
发布[通过使用添加到您的问题]您的确切异常及其抱怨的代码部分。什么是
inaray
,什么是i
?我猜超出范围的是从那里来的。我猜OOB是在访问printary
时出现的,它包含的子字符串比预期的少。除非您将此作为解析练习,否则存在多个。除了拆分字符串,您还可以与捕获组一起使用来提取所需的数据。例如,使用类似于“^\\s*(\\w+)\\s*=\\s*(.+),$”的正则表达式。
printArray = InArray[i].replaceAll("\\\\\"", "").trim().split(",(?=([^\"]*\"[^\"]*\")*(?![^\"]*\"))