Search code examples
androidstringsmsstrip

Android split Text / Numbers from SMS string


im making a gps tracking program and i receive an sms message with the following content

smsMessage="http://maps.google.com/maps?q=42.396068,13.45201,17 phone is outside the area"

Could anybody be so kind and tell me how i can split out only the needed longitude and the latitude from the sms string ?

thanx in advance


Solution

  • You could do like this,

    String s = "http://maps.google.com/maps?q=42.396068,13.45201,17 phone is outside the area";
    String parts[] = s.replaceAll("^.*?=|\\s.*", "").split(",(?=[-+]?\\d+\\.\\d+)");
    System.out.println(Arrays.toString(parts));
    

    output:

    [42.396068, 13.45201,17]