CodeItBetter Programming Another VB Programming Blog

How to Strip out extra tabs, CrLf and multiple spaces

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'String Manipulation - How to Strip out extra tabs, CrLf and multiple spaces
Public Function CleanString(strSource As String) As String
    'Purpose   :  Replace all occurences of tabs, CRLF and multiple spaces so 
    '             that words are separated by single spaces
    'Method    :  Repeatedly replace occurrences of 2 adjacent spaces with 1 
    '             space, until all multiple spaces are replaced
    'Inputs    :  strSource [the string to be 'filtered']
    'Outputs   :  returns the 'processed' string
    '
    '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, "  "))
        strSource = Replace$(strSource, "  ", " ")
    Loop
    'Remove any leading or training spaces and return result
    CleanString = Trim$(strSource)
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.