excel VBA Split()问题
Ge="j,k|n,o|r,s|v,w"如何用Split()得到下面的[多维]数组Ge(0,0)=jGe(0,1)=kGe(1,0)=nGe(1,1)=oGe(2,0)=...
Ge = "j,k|n,o|r,s|v,w"如何用Split()得到下面的[多维]数组Ge(0,0)=jGe(0,1)=kGe(1,0)=nGe(1,1)=oGe(2,0)=rGe(2,1)=s
展开
2个回答
2013-10-19
展开全部
Dim Ge, str, tmp
str = "j,k|n,o|r,s|v,w"
tmp = Split(str, ",")
ReDim Ge(UBound(tmp))
For i = 0 To UBound(Ge)
Ge(i) = Split(tmp(i), "|")
Next
Split只能返回一维数组,以上代码所得到的也是一维数组嵌套一维数组的结果,因此最后读取时,应当采用Ge(0)(0),而不是Ge(0,0) 。如果非要二维数组不可,那么需要对原来的字符串进行额外的处理。
str = "j,k|n,o|r,s|v,w"
tmp = Split(str, ",")
ReDim Ge(UBound(tmp))
For i = 0 To UBound(Ge)
Ge(i) = Split(tmp(i), "|")
Next
Split只能返回一维数组,以上代码所得到的也是一维数组嵌套一维数组的结果,因此最后读取时,应当采用Ge(0)(0),而不是Ge(0,0) 。如果非要二维数组不可,那么需要对原来的字符串进行额外的处理。
推荐于2018-11-20
展开全部
以前谢了一个模块来实现这种,给你瞧瞧
Sub test()
Dim xx
ge = "j,k|n,o|r,s|v,w"
xx = Text2arr(ge, "|", ",")
End Sub
Function Text2arr(ByVal sStr As String, cChr1, cChr2) As Variant
Dim tmpArr, Text2arr2, i As Double
tmpArr = Split(sStr, cChr1)
ReDim Text2arr2(UBound(tmpArr))
For i = 0 To UBound(tmpArr)
Text2arr2(i) = Split(tmpArr(i), cChr2)
Next
Text2arr = Text2arr2
End Function
Sub test()
Dim xx
ge = "j,k|n,o|r,s|v,w"
xx = Text2arr(ge, "|", ",")
End Sub
Function Text2arr(ByVal sStr As String, cChr1, cChr2) As Variant
Dim tmpArr, Text2arr2, i As Double
tmpArr = Split(sStr, cChr1)
ReDim Text2arr2(UBound(tmpArr))
For i = 0 To UBound(tmpArr)
Text2arr2(i) = Split(tmpArr(i), cChr2)
Next
Text2arr = Text2arr2
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询