Cut characters


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
39
'**********************************************************************************************************
' Name:                 cutChars
' Author:               mielk | 2013-05-15
'
' Comment:              Function cuts the specified number of characters at the end of the source string.
'
' Parameters:
'   text                String to be shortened.
'   chars               Number of characters to be cutted. It should be positive number.
'                       If this argument is 0 or negative number, the original string is returned without
'                       any changes.
'
' Returns:
'   String              The original string without the specified number of characters at the end of this
'                       string.
'
'                       Example:
'                       ?cutChars("String", 3) = "Str" <--- 3 characters have been cut from the original
'                                                           string "String")
'
'
' --- Changes log -----------------------------------------------------------------------------------------
' 2013-05-15    mielk       Method created.
'**********************************************************************************************************
Public Function cutChars(text As String, chars As Integer) As String
    Const METHOD_NAME As String = "cutChars"
    '------------------------------------------------------------------------------------------------------


    'Check if the number of characters to be cutted is not greater than the length of the base string.
    'If it is, return empty String.
    If chars > VBA.Len(text) Then
        cutChars = ""
    Else
        cutChars = VBA.Left$(text, VBA.Len(text) - chars)
    End If


End Function