Android Question Need help with string manipulation

siddsg

Member
Licensed User
Longtime User
Hello,
I need help with string manipulation in the following string:
"My current Location In Latitude & Longitude:12.924273214302957 - 77.66566847451031"

I want to assign the latitude and longitude numbers separately to different variables.

Note that since these are coordinates, the lengths of the two numbers can vary based on position, so cannot use fixed index values with substring.

Thanks!

Siddharth
 

NJDude

Expert
Licensed User
Longtime User
Try this:
B4X:
Dim myString As String
Dim Buffer() As String

myString = "My current Location In Latitude & Longitude:12.924273214302957 - 77.66566847451031"

Buffer = Regex.Split(":", myString)
Buffer = Regex.Split(" - ", Buffer(1))

Msgbox("Latitude: " & Buffer(0) & CRLF & "Longitude: " & Buffer(1), "")
 
Upvote 0

siddsg

Member
Licensed User
Longtime User
Thanks NJDude, that worked perfectly!
 
Upvote 0

siddsg

Member
Licensed User
Longtime User
Hello,
For the benefit of everyone, found and posting another way to do this...

B4X:
Dim Latitude as Int
Dim Longitude as Int
Dim ColonIndex As Int
Dim DashIndex As Int
 
ColonIndex =  Smstext.IndexOf(":")
DashIndex =  Smstext.IndexOf("-")
Latitude = Smstext.SubString2(ColonIndex + 1, DashIndex)
Longitude = Smstext.SubString(DashIndex + 1)
Log(Latitude & " " & Longitude)
 
Upvote 0
Top