Remove spaces


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'**********************************************************************************************************
' Name:                 removeSpaces
' Author:               mielk | 2012-11-18
'
' Comment:              Function to remove all the blank characters from the given string.
'
' Parameters:
'   text                String to be cleaned of blank characters.
'                       The given value must be of a String type or of any other type that can be
'                       converted to String.
'                       The following characters are considered by this function as blank:
'
'                                   Character               |  ASCII code
'                                   ------------------------|--------------
'                                   Horizontal Tab          |        9
'                                   Line Feed               |       10
'                                   Carriage Return         |       13
'                                   Space                   |       32
'                                   No-Break Space          |      160
'
' Returns:
'   String              The original text cleaned of blank characters.
'
'
' --- Changes log -----------------------------------------------------------------------------------------
' 2012-11-18        mielk           Function created.
'**********************************************************************************************************
Public Function removeSpaces(ByVal text As String) As String
    Const METHOD_NAME As String = "removeSpaces"
    '------------------------------------------------------------------------------------------------------

    removeSpaces = VBA.Replace(text, VBA.Chr$(9), "")               '..........................tab
    removeSpaces = VBA.Replace(removeSpaces, VBA.Chr$(10), "")      '.................... linefeed
    removeSpaces = VBA.Replace(removeSpaces, VBA.Chr$(13), "")      '.................... carriage
    removeSpaces = VBA.Replace(removeSpaces, VBA.Chr$(32), "")      '....................... space
    removeSpaces = VBA.Replace(removeSpaces, VBA.Chr$(160), "")     '....................... space

End Function