Copy Code code as follows:
' Get rid of consecutive carriage returns and spaces at the ends of a string
function Trimvbcrlf (str)
TRIMVBCRLF=RTRIMVBCRLF (Ltrimvbcrlf (str))
End Function
' Remove successive carriage returns and spaces at the beginning of the string
function Ltrimvbcrlf (str)
Dim Pos,isblankchar
Pos=1
Isblankchar=true
While Isblankchar
If mid (str,pos,1) = "" Then
Pos=pos+1
ElseIf Mid (str,pos,2) =vbcrlf Then
Pos=pos+2
Else
Isblankchar=false
End If
Wend
Ltrimvbcrlf=right (Str,len (str)-pos+1)
End Function
' Remove consecutive carriage returns and spaces at the end of the string
function Rtrimvbcrlf (str)
Dim Pos,isblankchar
Pos=len (str)
Isblankchar=true
While Isblankchar and pos>=2
If mid (str,pos,1) = "" Then
Pos=pos-1
ElseIf Mid (str,pos-1,2) =vbcrlf Then
Pos=pos-2
Else
Isblankchar=false
End If
Wend
Rtrimvbcrlf=rtrim (Left (Str,pos))
End Function