繁体   English   中英

Java我如何用许多双引号分隔字符串

[英]Java how do i split string by many double quote

我想拆分该字符串,我看到它是如此复杂。

“ GPSTime”:“ 2014年7月10日5:44:23 AM”

7/10/2014 5:44:23 AM

有什么帮助吗?

干得好:

首先,用":"分隔,然后从日期时间字符串中替换“ last "

String c= "\"GPSTime\":\"7/10/2014 5:44:23 AM\"";
String x= c.split("\":\"")[1];
System.out.println("final: "+x.replace("\"", ""));

输出:

08-07 14:54:21.931: I/System.out(20228): final: 7/10/2014 5:44:23 AM

使用以下内容:

String str[]=s.split("\":\"");

或者如果字符串的开头没有改变,您可以这样做:

String noDoubleQuotes = yourString.replace("\"", "");
String result = noDoubleQuotes .replace("GPSTime:", "");
public static void main(String[] args) {
    final String string = "\"GPSTime\":\"7/10/2014 5:44:23 AM\"";
    final String begin = "\":\"";
    final String end = "\"";
    final String substring = string.substring(string.indexOf(begin) + begin.length(), string.length() - end.length());

    System.out.println("substring = [" + substring + "]");
}

您必须使用:

String str[]=s.split("\":\"");

然后从结果中删除其余的"

将空格替换为“后,尝试按空格分割:

s = s.replace("\"", " ");
String str[]=s.split(" ");

然后,数组的最后一个元素应包含您想要的值。 请注意,在使用之前,您可能需要修剪特定的条目。

首先使用:作为分隔符

  String str[]=s.split(":");

然后选择正确的令牌以使用空格作为分隔符进行拆分

  String str2[]=s.split(" ");

然后,您有了str2中需要的三个元素。

您可以使用正则表达式,例如:

"GPSTime":"(.+)"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM