用VB怎么给一个字符串中每个字母之间加上空格?在线等!谢谢!

2025-01-02 19:19:54
推荐回答(2个)
回答1:

....这么长的函数? 有没有必要啊
把这个代码加到Command(按钮) 的单击事件

Dim StrA, TempStr As String, Fx As Long

StrA = "asdfzxcvqwer" '你要插入空格的字符串

For Fx = 1 To Len(StrA) '循环插入.
TempStr = TempStr & Mid(StrA, Fx, 1)
If Fx <> Len(StrA) Then TempStr = TempStr & " " '不要在最后加入空格.
Next

Print TempStr

回答2:

Private Function AddSp(ByVal str As String) As String
Dim Lstr As Long
Dim i As Long
Dim temp() As String * 1

Lstr = Len(str)

If Lstr - 1 < 1 Then AddSp = str: Exit Function
ReDim temp(1 To Lstr) As String * 1

For i = 1 To Lstr
temp(i) = Mid(str, i, 1)
Next

AddSp = temp(1)
For i = 2 To Lstr
AddSp = AddSp & " " & temp(i)
Next

End Function

我给你做了个加空格的函数,怎么调用因该会吧