stringvb6trim

Trim all types of whitespace, including tabs


In VB6, the Trim() function trims spaces off the front and back of a string. I am wondering if there is a function that will trim not just spaces, but all whitespace (tabs in this case) off of each end of a string.


Solution

  • It's a shame there is no built in function. Here is the one I wrote. It does the trick.

    Function TrimAllWhitespace(ByVal str As String)
    
        str = Trim(str)
    
        Do Until Not Left(str, 1) = Chr(9)
            str = Trim(Mid(str, 2, Len(str) - 1))
        Loop
    
        Do Until Not Right(str, 1) = Chr(9)
            str = Trim(Left(str, Len(str) - 1))
        Loop
    
        TrimAllWhitespace = str
    
    End Function