最后面可能有逗号,也可能没有,可能有一个也可能有多个,最之没有就不变,最后面有就都去掉(字符串中间的逗号保留)
第1个回答 2021-01-19
Sub test()
Dim a$
a = "我们,赶回家看,,,,,,"
Do While Right(a, 1) = "," Or Right(a, 1) = ","
a = Left(a, Len(a) - 1)
Loop
MsgBox a
End Sub
Dim a$
a = "我们,赶回家看,,,,,,"
Do While Right(a, 1) = "," Or Right(a, 1) = ","
a = Left(a, Len(a) - 1)
Loop
MsgBox a
End Sub
第2个回答 2021-01-19
vb.net只需要一句话,但是vba可以用同样的思路来做
xx = "1,2,3,4,,,"
Dim yy() As String
Dim zz As String
yy = VBA.Split(xx, ",")
ReDim NewArr(LBound(yy) To UBound(yy))
For i = LBound(yy) To UBound(yy)
If yy(i) <> "" Then
NewArr(j) = yy(i)
j = j + 1
End If
Next i
ReDim Preserve NewArr(LBound(yy) To j - 1)
zz = VBA.Join(NewArr, ",")本回答被网友采纳
xx = "1,2,3,4,,,"
Dim yy() As String
Dim zz As String
yy = VBA.Split(xx, ",")
ReDim NewArr(LBound(yy) To UBound(yy))
For i = LBound(yy) To UBound(yy)
If yy(i) <> "" Then
NewArr(j) = yy(i)
j = j + 1
End If
Next i
ReDim Preserve NewArr(LBound(yy) To j - 1)
zz = VBA.Join(NewArr, ",")本回答被网友采纳