How to Trim all Non-printing Characters from a given String
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 24 25 26 27 28 29 30 31 | 'String Manipulation - How to Trim all Non-printing Characters from a given String Option Explicit 'This function trims all nonprinting characters (tabs, character returns, spaces, etc.) Public Function TrimAll(ByVal sString As String) As String Dim sResult As String Dim lLength As Long, lCount As Long sResult = sString lLength = Len(sString) If lLength > 0 Then 'Ltrim For lCount = 1 To lLength If Asc(Mid$(sResult, lCount, 1)) > 32 Then Exit For Next lCount sResult = Mid$(sResult, lCount) lLength = Len(sResult) 'Rtrim If lLength > 0 Then For lCount = lLength To 1 Step -1 If Asc(Mid$(sResult, lCount, 1)) > 32 Then Exit For Next lCount End If sResult = Left$(sResult, lCount) End If TrimAll = sResult End Function |