Public Function Split(ByVal Sin As String, sOut() As String, _
Optional sDelim As String, Optional nLimit As Long = -1, _
Optional bCompare As VbCompareMethod = vbBinaryCompare) As _
Variant
Dim sRead As String, nC As Integer
If sDelim = "" Then sDelim = " "
If InStr(Sin, sDelim) = 0 Then
ReDim sOut(0) As String
sOut(0) = Sin
Split = sOut
Exit Function
End If
sRead = ReadUntil(Sin, sDelim, bCompare)
Do
ReDim Preserve sOut(nC)
sOut(nC) = sRead
nC = nC + 1
If nLimit <> -1 And nC >= nLimit Then Exit Do
sRead = ReadUntil(Sin, sDelim)
Loop While sRead <> "~TWA"
ReDim Preserve sOut(nC)
sOut(nC) = Sin
Split = sOut
End Function
Private Function ReadUntil(ByRef Sin As String, sDelim As _
String, Optional bCompare As VbCompareMethod = _
vbBinaryCompare) As String
Dim nPos As String
nPos = InStr(1, Sin, sDelim, bCompare)
If nPos > 0 Then
ReadUntil = Left(Sin, nPos - 1)
Sin = Mid(Sin, nPos + Len(sDelim))
Else
ReadUntil = "~TWA"
End If
End Function