CodeItBetter Programming Another VB Programming Blog

How to strip out leading and trailing characters (Extended Trim)

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'String Manipulation - How to strip out leading and trailing characters (Extended Trim)
'Extended Trim Function can strip off any leading, trailing, any number of specified characters.

Public Function ExtendedTrim(ByVal strLine As String, ByVal strCharacter As String) As String
    Dim I As Integer
    'To Strip Leading Characters
    For I = 1 To Len(strLine) Step Len(strCharacter)
        If Mid$(strLine, 1, Len(strCharacter)) = strCharacter Then
            strLine = Mid$(strLine, Len(strCharacter) + 1)
        Else
            Exit For
        End If
    Next I
    'To Strip Trailing Characters
    For I = Len(strLine) To 1 Step -Len(strCharacter)
        If Mid$(strLine, Len(strLine) - Len(strCharacter) + 1) = strCharacter Then
            strLine = Mid$(strLine, 1, Len(strLine) - Len(strCharacter))
        Else
            Exit For
        End If
    Next I
    ExtendedTrim = strLine
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.