Public Function trim_all(strallstring)
Dim b(65535), d(65535), str As String
Dim i As Long
Dim step As Long
step = Len(strallstring)
For i = 1 To step
b(i) = Mid(strallstring, i, 1)
Next
For i = 1 To step
If b(i) <> " " Then
d(i) = b(i)
str = str & d(i)
End If
Next
trim_all = str
End Function
我写了一个类似于"Trim,Rtrm,Ltrim"的函数。他的调用如下例:
Private Sub Command1_Click()
a = " ffvvv fff ffv"
Print trim_all(a)
End Sub
Function DelspaceStr(str As String) As String '去掉空格
Dim I As Integer
For I = 1 To Len(str)
If Mid(str, I, 1) <> " " Then DelspaceStr = DelspaceStr + Mid(str, I, 1)
Next
End Function
调用:
dim aaa as string
aaa="aaa bbb ccc ddd"
aaa=DelspaceStr(aaa)