Extracting numbers from text in a field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Extracting numbers from text in a field

Post by calmrr3 » Sat Jan 17, 2015 8:24 pm

Hello,

I am wondering if someone might help me with the following:

I have a .GPX file (tracked gps data text file)

The text file is a long list of tracked gps points which are listed like this:


<trkpt lat="55.9202360" lon="-3.2123590">
<ele>104.7</ele>
<time>2014-09-16T14:58:37Z</time>
</trkpt>

I want to be able to put the latitude points in a field purely as a list of numbers
and the same for the longitude points.

I am not concerned about elevation or time.

So in the latitude field it will show:

55.9202360
55.92... (whatever the next point is)
etc for each point

and the same for the longitude field.


I have a field where I can just copy the full gpx file as text and a button to start sorting it.

I think I will be using a repeat to cycle through each line of the next and possibly 'isNumber'
but other than that I am unsure how to go about this - especially because the numbers are decimals and some of them are negative numbers.

Any help is much appreciated!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Extracting numbers from text in a field

Post by Dixie » Sat Jan 17, 2015 8:41 pm

Hi...

Code: Select all

on mouseUp
   repeat for each line thisLine in fld 1
      if char 1 to 4 of thisLine = "<trk" then
         put thisLine into temp
         replace "<trkpt lat=" with empty in temp
         replace quote with empty in temp
         replace " lon=" with comma in temp
         replace ">" with empty in temp
         put temp & cr after fld 2
      end if
   end repeat
end mouseUp
put your data into fld 1... the mouseUp will retuen lat/lon separated by a comma

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Extracting numbers from text in a field

Post by calmrr3 » Sat Jan 17, 2015 10:07 pm

Thanks for your reply - is there a way of separating the number before the comma and the number after the comma so that the latitude and longitude values are added to separate lists in separate fields?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Extracting numbers from text in a field

Post by Dixie » Sat Jan 17, 2015 10:15 pm

Code: Select all

on mouseUp
   repeat for each line thisLine in fld 1
      if char 1 to 4 of thisLine = "<trk" then
         put thisLine into temp
         replace "<trkpt lat=" with empty in temp
         replace quote with empty in temp
         replace " lon=" with comma in temp
         replace ">" with empty in temp
         put item 1 of temp & cr after fld 2
         put item 2 of temp & cr after fld 3
      end if
   end repeat
end mouseUp

Post Reply