vb split 用法

2024-11-01 00:39:10
推荐回答(3个)
回答1:

Split(Split(s, ",")(i), ",")(0)输出是s字符串通过","分割后的第i个数组内的字符再次使用","分割后的第0个数组内的字符
比如s=",1,2,3,4,5,"
此时AllNum1(LineNum1)=5,LineNum1=1
For i = 1 To AllNum1(LineNum1)
NumberNum1(LineNum1, i) = Split(Split(s, ",")(i), ",")(0)
Next i
split过程如下
Split(s, ",")(0)=""
Split(s, ",")(1)="1"
Split(s, ",")(2)="2"
Split(s, ",")(3)="3"
Split(s, ",")(4)="4"
Split(s, ",")(5)="5"
Split(s, ",")(6)=""
外面再有一级split
是将上面分割的字符串再次通过 ","分割并取分割后的第一个字符

回答2:

觉得这代码有一点点问题
Split()返回一个按所给分割符切开的数组,如a=Split("a,b,c",",")得到
a(0)="a" a(1)="b" a(2)="c"

代码的字面意思是:循环1~AllNum1(LineNum1)过程中,给NumberNum1(LineNum1, i)赋值,值为a,其中:
用“,”分割s后所得的第i项,再用“,”分割此项取头项,将头项赋给a

问题是:第一个split返回的字符串数组不可能再含有","

试一下把Split(Split(s, ",")(i), ",")(0)改成Split(s, ",")(i)看结果相同不,怀疑外面的split不起作用。

回答3:

Split函数最后返回的结果是个数组
所以(0)就表示该数组的第一个元素值