Option Explicit
Public Function GetStringFromQuotation(sText As String, sDelimiter As String)
'Store the position of the 1st and 2nd delimiter in the String
Dim iPositionOfFirstDelimiter As Integer, iPositionOfSecondDelimiter As Integer
'Store the length of the delimiter
Dim iLenDelimiter As Integer
'Deliver nothing if the function doesn't get a single usable parameter
'otherwise you'd get an error later on
If Len(sText) = 0 And Len(sDelimiter) = 0 Then
GetStringFromQuotation = ""
Exit Function
End If
iLenDelimiter = Len(sDelimiter)
'Find 1st occurence of delimiter
iPositionOfFirstDelimiter = InStr(sText, sDelimiter)
'Find the 2nd one, starting right behind the first one
iPositionOfSecondDelimiter = InStr(iPositionOfFirstDelimiter + iLenDelimiter, _
sText, sDelimiter)
'If there are 2 occurences
If iPositionOfFirstDelimiter > 0 And iPositionOfSecondDelimiter > 0 Then
'Take the part of the string that's right between them
GetStringFromQuotation = Mid(sText, iPositionOfFirstDelimiter + iLenDelimiter, _
iPositionOfSecondDelimiter - iPositionOfFirstDelimiter - iLenDelimiter)
Else
GetStringFromQuotation = ""
End If
End Function
|