vb 删除字符串最后的换行符

2020-06-15 科技 75阅读
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
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com