I make a great deal of use of this utility function for parsing strings; especially useful in making collections of strings in INI files, such as the various colour codes for different parts of a GUI form (as we shall see).

Another use is splitting a sentence into words; although Word can do this within a document, I often want to do it in a user-string.

You may want to drop this into the module U.

<pre>Public Function strSplitStringAt(strIn As String, strDelim As String, boolDirection As Boolean)
' Procedure : strSplitStringAt
' Description: Return the leading or trailing portion of a string.
' Copyright: Chris Greaves Inc.
' Inputs: A string.
' A delimiter character.
' A directional flag True==>leading string
' Returns: A sub-string of the original string.
' Assumes: None.
' Side Effects: None.
' Tested: By the calls shown below.

' If the delimiter is found TRUE returns the first sub-string
' If the delimiter is found FALSE returns all but the first sub-string
' If the delimiter is not found TRUE returns the original string
' If the delimiter is not found FALSE returns the empty string

Dim lngI As Long
If strDelim = "" Then
strSplitStringAt = ""
lngI = InStr(1, strIn, Left(strDelim, 1))
If lngI > 0 Then
If boolDirection Then
strSplitStringAt = Left(strIn, lngI - 1)
strSplitStringAt = Right(strIn, Len(strIn) - lngI)
End If
If boolDirection Then
strSplitStringAt = strIn
strSplitStringAt = ""
End If
End If
End If
'Sub TESTstrSplitStringAt()
'MsgBox strSplitStringAt("here,is,a,string", ",", True) ' "here"
'MsgBox strSplitStringAt("here,is,a,string", ",", False) ' "is,a,string"
'MsgBox strSplitStringAt("string", ",", True) ' "string"
'MsgBox strSplitStringAt("string", ",", False) ' ""
'End Sub
End Function