2

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 ")"

1

2 Answers 2

2

Use Split:

FirstValue = Split(Split(s, "F) ")(1), " G)")(0)
SecondValue = Split(Split(s, "G) ")(1), ")")(0)
Sign up to request clarification or add additional context in comments.

Comments

0

Use this function -

Public Function fParseXML(sTag01 As String, sTag02 As String, sToParse As String) As String
 Dim pStart As Integer
 Dim pEnd As Integer
 Dim pLen As Integer
 If InStr(1, sToParse, sTag01) Then
  pStart = InStr(1, sToParse, sTag01) + Len(sTag01)
  pEnd = InStr(pStart, sToParse, sTag02)
  pLen = pEnd - pStart
  fParseXML = Mid(sToParse, pStart, pLen)
  Exit Function
 Else
  fParseXML = "Not found" & "**" & sTag01 & "**" & Mid(sToParse, 1, 100)
  Exit Function
 End If

use F) and G) and ) as the tags.

2 Comments

Thanks, it works, but when I try to change tag to "G)" and ")" i get an error in fParseXML = Mid(sToParse, pStart, pLen)
@Vitaly Sorry I should have tested it first. Code changed and it works for me now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.