my strings would be <one> some text<two>some more text<three>and
more text<four>
So I am not sure about getToken([collumn name], 3) because I
would not know the interger and plus I want to remove all the
tags.
Slightly more than Air Code (written in Access, tested in Access):
Public Function StripTokens(strStartChar As String, _
strEndChar As String, varInput As Variant) As Variant
Dim strTemp As String
Dim lngStart As Long
Dim lngEnd As Long
Dim strOutput As String
If Not IsNull(varInput) And Len(strStartChar) > 0 _
And Len(strEndChar) > 0 Then
strTemp = varInput
If Left(strTemp, 1) = strStartChar Then
strTemp = Mid(strTemp, InStr(strTemp, strEndChar) + 1)
End If
Do While InStr(strTemp, strStartChar) > 0
lngStart = InStr(strTemp, strStartChar)
lngEnd = InStr(strTemp, strEndChar)
strOutput = strOutput & Left(strTemp, lngStart - 1)
strTemp = Mid(strTemp, lngEnd + 1)
Loop
strOutput = strOutput & strTemp
StripTokens = strOutput
End If
End Function
Now, one problem is that your input text:
"<one> some text<two>some more text<three>and more text <four>"
....will come out without nice-looking spaces:
" some textsome more textand more text "
....and with leading and trailing spaces. The latter are easily
gotten rid of with a Trim() on the last line of the function:
StripTokens = Trim(strOutput)
But the other is much harder, but surely with that framework, you
should be able to handle it.
One solution might be the array-based approach (using Split()):
Public Function StripTokensA(strStartChar As String, _
strEndChar As String, varInput As Variant) As Variant
Dim strTemp() As String
Dim l As Long
Dim strTest As String
Dim lngEnd As Long
Dim strOutput As String
If Not IsNull(varInput) And Len(strStartChar) > 0 _
And Len(strEndChar) > 0 Then
strTemp = Split(varInput, strStartChar)
For l = 0 To UBound(strTemp()) - 1
strTest = strTemp(l)
lngEnd = InStr(strTest, strEndChar)
If lngEnd = 0 Then
strOutput = Trim(strOutput & " " & strTest)
Else
strOutput = Trim(strOutput & " " _
& Trim(Mid(strTest, lngEnd + 1)))
End If
Next l
StripTokensA = strOutput
End If
End Function
This one is pretty solid, seems to me.
I don't know how either one of them fares performance-wise, though.