简体   繁体   English

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

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

I want to split that string and i see its so complictaed. 我想拆分该字符串,我看到它是如此复杂。

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

Into

7/10/2014 5:44:23 AM

any help ? 有什么帮助吗?

Here you go: 干得好:

Firstly, split by ":" and then replace last " from the date time string. 首先,用":"分隔,然后从日期时间字符串中替换“ last "

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

Output: 输出:

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

Use the following : 使用以下内容:

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

or you could do this if the start of the string doesn't change : 或者如果字符串的开头没有改变,您可以这样做:

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 + "]");
}

You have to use: 您必须使用:

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

And then you remove the remaining " from your result. 然后从结果中删除其余的"

Try splitting by white spaces after replacing " with them: 将空格替换为“后,尝试按空格分割:

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

The array's last elements should then contain your desired values. 然后,数组的最后一个元素应包含您想要的值。 Note that you may need to trim the specific entries before use. 请注意,在使用之前,您可能需要修剪特定的条目。

Split first using : as separator 首先使用:作为分隔符

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

And then choose the right token to split using space as separator 然后选择正确的令牌以使用空格作为分隔符进行拆分

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

And then you have the three elements that you need in str2. 然后,您有了str2中需要的三个元素。

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

"GPSTime":"(.+)"

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

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