前端设计

VB中Split函数的用法

2014-06-13

问:比如a="1,2,3,4,5",我想把1,2,3,4,5分别取出,用x=Split(a,",")这样写对不对,
x的值是什么?也就是怎么样得到1,2,3……

回答:

Dim x() as Variant

a="1,2,3,4,5"
x=Split(a,",")

 

 

a="1,2,3,4,5"
m1 = Split(a,",")(0) //1
m2 = Split(a,",")(1) //2
m3 = Split(a,",")(2) //3
m4 = Split(a,",")(3) //4
m5 = Split(a,",")(4) //5

 

 

Private Sub Command1_Click()
Dim i As Integer
Dim strAll As String
Dim strCity() As String
    strAll = "1,2,3,4,5"
    strCity = Split(strAll, ",", , vbTextCompare)
    For i = 0 To UBound(strCity)
        List1.AddItem strCity(i)
    Next
End Sub
'VB6.0通过 VB5.0通不过