我有一些文本文件,我需要读出双引号字符串。我尝试使用split()
方法,但我没有得到我想要的东西。示例:
"000ABCD",000,HU,4614.850N,02005.483E,80.0m,5,160,1185.0m,,005,4619.650N,01958.400E,87.0m,1...
在这个例子中,我只需要字符串000ABCD
。有什么想法吗?
答案 0 :(得分:3)
您可以使用此正则表达式:
"\\"(.*?)\\""
Pattern pattern = Pattern.compile("\\"(.*?)\\"");
Matcher matcher = pattern.matcher("\"000ABCD\",000,HU,4614.850N,02005.");
if (matcher.find()) {
System.out.println(matcher.group(1));
}
它将打印:000ABCD。
答案 1 :(得分:1)
int firstIndex = oldString.indexOf('"');
String data = oldString.substring(firstIndex+1, oldString.indexOf('"', firstIndex);
答案 2 :(得分:1)
试试这个
String str="\"000ABCD\",000,HU,4614.850N,02005.483E,80.0m,5,160,1185.0m,,005,4619.650N,01958.400E,87.0m,1";
Pattern p = Pattern.compile("\"(.*?)\"");
Matcher m = p.matcher(str);
while (m.find()) {
System.out.println(m.group(1));
}