how can i split the particular data from a string?

时间:2015-06-30 19:22:16

标签: android string

I am getting the lat-long from the current location now how can i split the only lat long values from a given string :- "lat/lng: (23.0326542,72.5279697)"? i want to get only "23.0326542,72.5279697".

2 个答案:

答案 0 :(得分:1)

试试这个:

   String line = "lat/lng: (23.0326542,72.5279697)";
        String[] array = line.split(",");

        for (int i = 0; i < array.length; i++) {
            Pattern pattern = Pattern.compile("(\\d+\\.\\d+)|(\\d+)");
            Matcher m = pattern.matcher(array[i]);
            if (m.find()) {
                System.out.println(m.group(1));
            }
      }

答案 1 :(得分:0)

It looks like you should be taking the substring of this string, from the beginning of the value you need, to the length of the string.