Public Function CleanString(strSource As String) As String
On Error GoTo CleanStringErr
' convert tabs to spaces first
strSource = Replace(strSource, vbTab, " ")
' convert all CRLFs to spaces
strSource = Replace(strSource, vbCrLf, " ")
' Find and replace any occurences of multiple spaces
Do While (InStr(strSource, " "))
' if true, the string still contains double spaces,
' replace with single space
strSource = Replace(strSource, " ", " ")
Loop
' Remove any leading or training spaces and return
' result
CleanString = Trim(strSource)
Exit Function
CleanStringErr:
' Insert error-handling code here
End Function
|