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

Related posts:

  1. How to remove Leading/Trailing Spaces from the String
  2. How to Trim all Non-printing Characters from a given String
  3. How to Strip special characters from a given String
  4. How to trim characters from the Beginning or End of a string
  5. How to trim characters from the Beginning of a string
  6. How to trim characters from the End of a string
  7. How to Strip/Remove Text from a given String
  8. How to Strip out extra tabs, CrLf and multiple spaces
  9. How to Strip Alphabets from a string
  10. How to Strip the Null Terminator from a given String

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.