1

我有一些文本文件,我只需要读出双引号字符串。我正在尝试split()方法,但我没有得到我想要的。例子:

"000ABCD",000,HU,4614.850N,02005.483E,80.0m,5,160,1185.0m,,005,4619.650N,01958.400E,87.0m,1...

在这个例子中,我只需要 string 000ABCD。有任何想法吗?

4

3 回答 3

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。

于 2013-07-11T09:31:08.367 回答
1
int firstIndex = oldString.indexOf('"');
String data = oldString.substring(firstIndex+1, oldString.indexOf('"', firstIndex);
于 2013-07-11T09:36:11.010 回答
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));
    }
于 2013-07-11T09:43:43.483 回答