Page 1 of 1

indexOf returns incorrect result

Posted: 23 Sep 2019 18:50
by turkert
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.

Re: indexOf returns incorrect result

Posted: 23 Sep 2019 22:00
by Horschte
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.

Re: indexOf returns incorrect result

Posted: 27 Sep 2019 18:06
by Desmanto
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)