indexOf returns incorrect result

Post your questions and help other users.

Moderator: Martin

Post Reply
turkert
Posts: 3
Joined: 14 Apr 2016 12:20

indexOf returns incorrect result

Post by turkert » 23 Sep 2019 18:50

Hello,
I've stored my current location in the "location" string. It is currently something like "40.245,29.085".
I need to change the longtitude and langtitude values from the location string.

I've tried to get the comma location by using indexOf like this but it returns 23. It should be 9.
X=indexOf(location, ",");

Then I've tried to split it,
X=split(location, ",")[0];
But it returns "Location[fused 40***"

Then I've tried
X=left(location, 9);
But it also returns "Location[fused 40***"

Most probably I've missed something.

How can I performs split, indexOf, left operations on string?

Regards.

Horschte
Posts: 56
Joined: 03 Nov 2014 18:00

Re: indexOf returns incorrect result

Post by Horschte » 23 Sep 2019 22:00

Use a debug dialog to check the variable "location", click on it and select "Show value in text editor". You will see that the value of the variable is in a special format. You have to format it first.

Code: Select all

loc = "{location,locationformat,decimal}";
Now you can use indexOf on "loc" to get the position of the comma or split to separate lat and lng.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: indexOf returns incorrect result

Post by Desmanto » 27 Sep 2019 18:06

To add on, you can then split the {loc} to get the lat and long.

Code: Select all

location = newLocation(40.245, 29.085);
loc = "{location,locationformat,decimal}";

lat = split(loc, ",")[0];
lon = split(loc, ",")[1];
lat will be 40.245 and lon will be 29.085. You can do aritmethic operation on it and then recreate back the location using newLocation(lat, lon)
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply