trim只能去除空字符,replace去除了所有的vbcrlf,要考虑保留字符串中间的vbcrlf,还要考虑字符串最后的换行符可能会有多个...如下是个思路:
Function myTrim(ByVal s As String) As String
Dim Length As Long
Dim Char As String
s = Trim(s)
Length = Len(s) + 1
Do
Length = Length - 1
Char = Mid(s, Length, 1)
Loop Until Char <> vbCr And Char <> vbLf
myTrim = Mid(s, 1, Length)
End Function
'测试
Private Sub Command1_Click()
Dim s As String
s = "ABC" & vbCrLf & vbCrLf
Debug.Print myTrim(s); Len(myTrim(s))
End Sub