VB.NET读取固定格式TXT文件数据为二维数组的方法
比如说如下一个文本文件:1,2,34,5,67,8,9数据中间间隔为“,”,每一行换行符用回车。我希望能够读入一个二位数组中,然后用此二维数组填充DataTable。希望...
比如说如下一个文本文件:
1,2,3
4,5,6
7,8,9
数据中间间隔为“,”,每一行换行符用回车。我希望能够读入一个二位数组中,然后用此二维数组填充DataTable。希望各位高手帮忙解决一下,给出源代码,谢谢。 展开
1,2,3
4,5,6
7,8,9
数据中间间隔为“,”,每一行换行符用回车。我希望能够读入一个二位数组中,然后用此二维数组填充DataTable。希望各位高手帮忙解决一下,给出源代码,谢谢。 展开
1个回答
展开全部
Dim rootlist() As String
Dim data(0, 0) As String
Dim tmp() As String
Dim listLengh As Int32
Dim I As Integer, II As Integer
rootlist = Split(IO.File.OpenText("C:/001.txt").ReadToEnd, vbCrLf)
listLengh = UBound(rootlist)
ReDim data(listLengh, 0)
For I = 0 To listLengh
tmp = Split(rootlist(I), ",")
ReDim Preserve data(listLengh, UBound(tmp))
For II = 0 To UBound(tmp)
data(I, II) = tmp(II)
Next
Next
For I = 0 To 2
For II = 0 To 2
MsgBox(data(I, II))
Next
Next
Dim data(0, 0) As String
Dim tmp() As String
Dim listLengh As Int32
Dim I As Integer, II As Integer
rootlist = Split(IO.File.OpenText("C:/001.txt").ReadToEnd, vbCrLf)
listLengh = UBound(rootlist)
ReDim data(listLengh, 0)
For I = 0 To listLengh
tmp = Split(rootlist(I), ",")
ReDim Preserve data(listLengh, UBound(tmp))
For II = 0 To UBound(tmp)
data(I, II) = tmp(II)
Next
Next
For I = 0 To 2
For II = 0 To 2
MsgBox(data(I, II))
Next
Next
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询