求教下是否有这样的函数
是否有这样一个函数:将一个字符串的所有字符之间添加上空格
如:
abcdefghi...xyz变成a b c d e f ... x y z
如果有,能告诉我这个函数的使用格式么?
如果没有,劳烦一下有其他方式实现这种目的么?
Option Explicit Private Sub Form_Load() Dim s As String s = "abcdefghijklmnopqrstuvwxyz" Dim t1 As Date Dim t2 As Date Dim t3 As Date Dim r As String Dim i As Long t3 = Now For i = 1 To 1000000 r = s1(s) Next i t1 = Now - t3 t3 = Now For i = 1 To 1000000 r = s2(s) Next i t2 = Now - t3 Debug.Print t1 Debug.Print t2 '我的测试结果 '0:00:14 '0:00:13 End Sub Public Function s1(cs As String) As String Dim b() As Byte Dim i As Long b = StrConv(cs, vbUnicode) '转BYTE数组 For i = 0 To UBound(b) '0值变成 32 If b(i) = 0 Then b(i) = 32 Next i s1 = StrConv(b, vbUnicode) '转回字符串 s1 = Replace(s1, " ", " ") '我测试在64位系统下,Unicode 是4字节,会造成3个空格,干掉。 End Function Public Function s2(cs As String) As String Dim i As Long For i = 1 To Len(cs) s2 = s2 & Mid(cs, i, 1) & " " '取每个字符,加空格,然后拼起来 Next i End Function