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:
- How to remove Leading/Trailing Spaces from the String
- How to Trim all Non-printing Characters from a given String
- How to Strip special characters from a given String
- How to trim characters from the Beginning or End of a string
- How to trim characters from the Beginning of a string
- How to trim characters from the End of a string
- How to Strip/Remove Text from a given String
- How to Strip out extra tabs, CrLf and multiple spaces
- How to Strip Alphabets from a string
- How to Strip the Null Terminator from a given String