主题:[原创]怎样将字符串转化为数组?
lcrxl1815
[专家分:110] 发布于 2008-09-03 06:32:00
dim buf as variant
buf="123.56"
怎样把buf转化为 :ary(0)=1,ary(1)=2,ary(2)=3,ary(3)=.,ary(4)=5,ary(5)=6,
回复列表 (共11个回复)
沙发
一江秋水 [专家分:9680] 发布于 2008-09-03 08:13:00
for i=1 to len(buf): ary(i-1)=mid(buf,i,1): next
板凳
joforn [专家分:1460] 发布于 2008-09-03 09:23:00
Dim Buf() As Byte
Dim I As Long
Buf = StrConv("123.56", vbFromUnicode)
For I = 0 To UBound(A)
Debug.Print Chr(Buf(I))
Next
3 楼
LUANJINLING [专家分:450] 发布于 2008-09-03 09:38:00
我赞成1楼的,简捷明白实用!
4 楼
lcrxl1815 [专家分:110] 发布于 2008-09-03 18:42:00
我也想赞成一楼的,可是运行不过去呀!
5 楼
lcrxl1815 [专家分:110] 发布于 2008-09-03 18:54:00
Private Sub Form_Load()
Dim i As Long
Dim buf As String
Dim ary() As String
buf = "12356"
For i = 0 To Len(buf) - 1
ary(i) = Mid(buf, i, 1)
Next
For i = Len(buf) - 1 To 0 Step -1
Debug.Print ary(i)
Next
End Sub
可是运行不过去呀!
6 楼
lcrxl1815 [专家分:110] 发布于 2008-09-03 19:03:00
谢谢joforn
7 楼
我是大喊三 [专家分:3010] 发布于 2008-09-03 19:04:00
好象还有split函数也可起到类似2楼程序的效果?
8 楼
lcrxl1815 [专家分:110] 发布于 2008-09-03 19:10:00
我查了一下VB常见的函数, 可以,mid和split都可以,就是不知道怎用?
9 楼
joforn [专家分:1460] 发布于 2008-09-03 20:23:00
[quote]Private Sub Form_Load()
Dim i As Long
Dim buf As String
Dim ary() As String
buf = "12356"
For i = 0 To Len(buf) - 1
ary(i) = Mid(buf, i, 1)
Next
For i = Len(buf) - 1 To 0 Step -1
Debug.Print ary(i)
Next
End Sub
可是运行不过去呀!
[/quote]
Private Sub Form_Load()
Dim i As Long
Dim buf As String
Dim ary() As String
buf = "12356"
redim ary(len(buf)-1)
For i = 1 To Len(buf)
ary(i-1) = Mid(buf, i, 1)
Next
For i = 0 To ubound(ary)
Debug.Print ary(i)
Next
End Sub
10 楼
joforn [专家分:1460] 发布于 2008-09-03 20:25:00
这所以用Byte数组是因为如果你转成数级后如果还要做其它的操作的话速度会快些。
我来回复