Abundant Technologies - IT Consulting Experts

 Source Code Library

 Code Details

 
'********************************************************************************* ' Procedures: TrimWhitespace ' Purpose: Removes all trailing white space from a string ' defaults to LF, CR, Tab, & space '********************************************************************************* Private Function TrimWhitespace(ByVal source As String, Optional ByVal whiteSpace As String) As String Dim curPos As Long Dim length As Long Dim first As Long Dim last As Long 'Defaults to CRs LFs tabs or spaces If whiteSpace = "" Then whiteSpace = Chr(10) + Chr(13) + Chr(32) + Chr(7) length = Len(source) 'finds first character that is not white space For first = 1 To length 'checks if current character appears in whitespace list If InStr(1, whiteSpace, Mid(source, first, 1)) = 0 Then Exit For Next first 'returns empty string if string is entirely whitespace If first = length + 1 Then TrimWhitespace = "" Exit Function End If 'finds last character that isn't whitespace For last = length To 1 Step -1 'checks if current character appears in whitespace list If InStr(1, whiteSpace, Mid(source, last, 1)) = 0 Then Exit For Next last 'returns part that is not whitespace TrimWhitespace = Mid(source, first, last - first + 1) End Function

Mail To: info@3pc.com