VBA extrahovat text mezi závorkami

Příklady kódu

0
0

VBA extrahovat text mezi závorkami

' Returns first text between pOpen and pClose (both can't contain "/" character...)
Function ExtractTag(pSource As String, pOpen As String, pClose As String)
    Dim startC As Long, endC As Long
    startC = InStr(1, pSource, pOpen) + Len(pOpen)
    endC = InStr(1, pSource, pClose)
    If startC > 0 And Len(pSource) - startC - (Len(pSource) - endC) > 0 Then
        ExtractTag = Mid(pSource, startC, _
      		Len(pSource) - startC - (Len(pSource) - endC))
    End If
End Function
' --------------------------------------------------------------------------------------
Sub TestMe()
    Debug.Print ExtractTag("Weather is [tag]fine[#tag].", "[tag]", "[#tag]")    ' fine
    Debug.Print ExtractTag("Value(banana).", "(", ")")                          ' banana
    Debug.Print ExtractTag("Value{banana}.", "{", "}")                          ' banana
End Sub

Související stránky

Související stránky s příklady

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................