请问怎么把字符串数据放到数组
请问一下,现在buffer里面接收了22 33 56 68这样的字符串数据,我现在想把他放到一个datatemp()数组里面,怎么用vb编程实现呀?就是怎么把字符串数据放到数组里面,非常感谢
'这种方法可以检测多位结构相同的数据,如果结构不同,你可以适当修改就可以了 Dim I As Integer, SS As String, X As Integer, Y As Integer, AA(1 To 20) As String, BB(1 To 20) As Integer '二个数组的下标可以根据需要修改即可 SS = "22 33 56 68" X = Len(SS) For I = 1 To X Step 3 '根据这个SS特定的数据结构可以这样,数据结构不同,不能这样 If InStr(I, SS, " ", 1) > 0 Then Y = Y + 1 BB(Y) = InStr(I, SS, " ", 1) AA(Y) = Left(SS, BB(Y) - 1) End If Next I If BB(Y + 1) = 0 Then BB(Y + 1) = X If AA(Y + 1) = "" Then AA(Y + 1) = SS For I = 1 To Y + 1 If I = 1 Then AA(I) = AA(I) If I > 1 Then AA(I) = Right(AA(I), BB(I) - BB(I - 1)) Next I '现在在数组AA中已经存储了这些被提取的数据,你可以使用数组的数据了。
Dim SS As String, AA, X As Integer SS = "22 33 56 68" AA = Split(SS, " ", -1, 1) '使用 Split 函数分组 X = UBound(AA) For I = 0 To X Text1.Text = Text1.Text & AA(I) & Space(3) Next I
[此贴子已经被作者于2016-5-11 13:44编辑过]