我从文件中有几个这样的字符串,我的代码告诉它用逗号分隔每一行,如果一行是作者,输出它,如果它是标题输出,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{\"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(",");
此
//InArray[i]=InArray[i].replaceAll("[{}]","").replaceAll("[\\\"]", "");
printArray = InArray[i].trim().split( ",(?=([^\"]*\"[^\"]*\")*(?![^\"]*\"))" ,-1);
但我不断获得index out of bound exception
答案 0 :(得分:0)
我基本上这样做是为了解决这个问题。
printArray = InArray[i].replaceAll("\\\\\"", "").trim().split(",(?=([^\"]*\"[^\"]*\")*(?![^\"]*\"))