2个回答
展开全部
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
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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询