|
-
Mar 8th, 2010, 09:40 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Extract values from string
Have following string:
PHP Code:
Feed.SmulocV2.Equipment,CAT,,DFT08783,2567,Hours,2010-02-07 06:37:41,Lat:35.10495,Lng:-82.99304
The string will always have text "Lat:" and "Lng:". The value of Lat and Lng could in some cases be nothing.
Now I need to extract the values for Lat and Lng. Any good way of doing this? Thank you.
Last edited by snufse; Mar 8th, 2010 at 09:44 AM.
-
Mar 8th, 2010, 09:45 AM
#2
Re: Extract values from string
Untested:
Code:
'~~> This function will give you the value of Lat
'~~> strOne = "Lat:"
'~~> strTwo = ",Lng:"
Private Function ExtractText(ByVal Source As String, _
ByVal strOne As String, ByVal strTwo As String) As String
Dim lngRet As long = Source.IndexOf(strOne) + strOne.Length
Return Source.Substring(lngRet, Source.IndexOf(strTwo) - lngRet)
End Function
Similarly you can find the position of "Lng:-" and get the text after that.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 8th, 2010, 09:48 AM
#3
Re: Extract values from string
you can do it with regex:
vb Code:
Dim testStr As String = "Feed.SmulocV2.Equipment,CAT,,DFT08783,2567,Hours,2010-02-07 06:37:41,Lat:35.10495,Lng:-82.99304"
'latitude
Dim rx As New Regex("(?<=Lat:)-*\d*\.*\d+")
MsgBox(rx.Match(testStr).Value)
'longitude
rx = New Regex("(?<=Lng:)-*\d*\.*\d+")
MsgBox(rx.Match(testStr).Value)
don't forget to import regex:
vb Code:
Imports System.Text.RegularExpressions
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 8th, 2010, 09:59 AM
#4
Thread Starter
Fanatic Member
Re: Extract values from string
-
Mar 8th, 2010, 10:01 AM
#5
Re: Extract values from string
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 8th, 2010, 10:02 AM
#6
Re: Extract values from string
 Originally Posted by snufse
OK, I get the correct value for Lat. Msgbox shows nothing for Lng.
Yes like I mentioned that function is for Lat only. You will have to write a different piece of code for Lan...
Give it a try... if you get stuck then post the code that you have tried and we will definitely help you
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Apr 8th, 2012, 03:58 PM
#7
PowerPoster
Re: Extract values from string
 Originally Posted by koolsid
Untested:
Code:
'~~> This function will give you the value of Lat
'~~> strOne = "Lat:"
'~~> strTwo = ",Lng:"
Private Function ExtractText(ByVal Source As String, _
ByVal strOne As String, ByVal strTwo As String) As String
Dim lngRet As long = Source.IndexOf(strOne) + strOne.Length
Return Source.Substring(lngRet, Source.IndexOf(strTwo) - lngRet)
End Function
Similarly you can find the position of "Lng:-" and get the text after that.
Hi friend i need exactly but for vb6b classic 
Sorry if i reply on old post
-
Apr 8th, 2012, 04:15 PM
#8
Re: [RESOLVED] Extract values from string
try this:
vb Code:
Private Function ExtractText(ByVal Source As String, ByVal strOne As String, ByVal strTwo As String) As String
Dim intRet As Integer = InStr(Source, strOne) + Len(strOne)
ExtractText = Mid(Source, intRet, InStr(Source, strTwo) - intRet)
End Function
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 8th, 2012, 04:51 PM
#9
PowerPoster
Re: [RESOLVED] Extract values from string
 Originally Posted by .paul.
try this:
vb Code:
Private Function ExtractText(ByVal Source As String, ByVal strOne As String, ByVal strTwo As String) As String
Dim intRet As Integer = InStr(Source, strOne) + Len(strOne)
ExtractText = Mid(Source, intRet, InStr(Source, strTwo) - intRet)
End Function
Hi friend i need exactly but for vb6b classic
Sorry if i reply on old post
-
Apr 8th, 2012, 04:55 PM
#10
Re: [RESOLVED] Extract values from string
that is for vb6... try it
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2012, 05:09 AM
#11
PowerPoster
Re: [RESOLVED] Extract values from string
-
Apr 9th, 2012, 09:39 AM
#12
Re: [RESOLVED] Extract values from string
vb Code:
Private Function ExtractText(ByVal Source As String, ByVal strOne As String, ByVal strTwo As String) As String
Dim intRet As Integer
intRet = InStr(Source, strOne) + Len(strOne)
ExtractText = Mid(Source, intRet, InStr(Source, strTwo) - intRet)
End Function
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|