字符串转数组
一串字符串、在VB6.0里怎么赋值到一个数组?
像这种:aaaaaaaabbbbbbbbccccccccdddddddd
没有分隔符。我要2个为一位。、
[解决办法]
Option Explicit
Private Sub Command1_Click()
Dim a$, i&, tem$()
a = "aaaaaaaabbbbbbbbccccccccdddddddds"
tem = GetArray(a, 2)
For i = LBound(tem) To UBound(tem)
Debug.Print tem(i)
Next i
End Sub
Function GetArray(ByVal BaseStr$, ByVal ChrLen&) As String()
Dim i&, tem$()
ReDim tem(Len(BaseStr) \ ChrLen)
For i = 1 To Len(BaseStr) Step ChrLen
'If i + ChrLen > Len(BaseStr) Then Exit For '字符串长度是奇数时,不提取最后一个字符,当然也可以前期处理
tem(i \ ChrLen) = Mid(BaseStr, i, ChrLen)
Next i
GetArray = tem
End Function