Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

parse out text typed in one text box into two separate text boxes

I have a text box that users paste GPS cordinates into.  They enter :
Latitude: 42.079964  /  Longitude: -71.869398
into field "GPSCOORDINATES".  I would like it parsed out into two separate fields : Latitude & Longitude.
any ideas ?

Regards,
Mark
0
drelinger
Asked:
drelinger
1 Solution
 
brad2575Commented:
you can split it into an array

arrayVairable = Split(FormFieldWithGPS, '/')

this should give you a 2 array variable then you would acccess it like this:

Lattitude = arrayVariable[0]
Longitude =  arrayVariable[1]

0
 
sh0eCommented:

<script>
function parseGPS(gps_string){
	matches = gps_string.match('Latitude: (-?[0-9]+\\.[0-9]+)  /  Longitude: (-?[0-9]+\\.[0-9]+)');
	if(matches == null || matches.length != 3){
		alert('invalid GPS coordinates');
	}
	else{
		var latitude = matches[1];
		var longitude = matches[2];
		alert(latitude + ":" + longitude);
	}
}
</script>
 
<input type="button" value="grab GPS" onClick="parseGPS(document.getElementById('GPSCOORDINATES').value);"></input>
<input type="text" id="GPSCOORDINATES"></input>

Open in new window

0
 
hieloCommented:
try:
Dim str
str="Latitude: 42.079964  /  Longitude: -71.869398" 
data = Split(str,"/")
data(0)=split(trim(data(0))," ")
data(1)=split(trim(data(1))," ")
Dim latitude,longitude
If "LATITUDE" = Left(Trim(UCase(data(0)(0))),8) Then
	latitude = data(0)(1)
	longitude= data(1)(1)
Else
	latitude = data(1)(1)
	longitude= data(0)(1)
End If 
Response.Write( "Lat: " & latitude )
Response.Write( "Long:" & longitude )

Open in new window

0
 
drelingerAuthor Commented:
I think all of the answers would work, but I felt this solution was the best.  Thank you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now