please have at look on my issue.
I have following string "F) GND G) FL240)"
in my Control.
I'm trying to parse the string between "F)" and "G)" and also between "G)" and ")" with following code
If Left(s, 2) = "F)" Then
'Task - Filled ItemF with value "GND" or other values between "F)" and "G)"
ItemF = Mid(s, InStr(s, "F)") 3, Len(s) - InStr(s, "G)"))
'or
'ItemF = Mid(s, InStr(s, "F)") 3, Len(s) - Len(Right(s, InStr(s, "G)"))))
'Task - Filled ItemG with value "FL240" or other values between "G)" and ")"
ItemG = Mid(s, InStr(s, "G)") 3, Len(s) - InStr(s, "G)")) - how I can exclude last ")"
End If
Could you explain please, how to separate and parse values between "F)" and "G)" and also between "G)" and ")"
CodePudding user response:
Use Split
:
FirstValue = Split(Split(s, "F) ")(1), " G)")(0)
SecondValue = Split(Split(s, "G) ")(1), ")")(0)
CodePudding user response:
Use this function -
Public Function fParseXML(sTag01 As String, sTag02 As String, sToParse As String) As String
Dim pStart As Integer
Dim pLen As Integer
If InStr(1, sToParse, sTag01) Then
pStart = InStr(1, sToParse, sTag01) Len(sTag01)
pLen = InStr(1, sToParse, sTag02) - pStart
fParseXML = Mid(sToParse, pStart, pLen)
Exit Function
Else
fParseXML = "Not found" & "**" & sTag01 & "**" & Mid(sToParse, 1, 100)
Exit Function
End If
End Function
use F) and G) as the tags.