vb.net读取固定格式txt文件

vb.net读取固定格式txt文件并写入listview格式例如:11111-22222... vb.net读取固定格式txt文件并写入listview
格式例如:
11111-22222
展开
 我来答
zhaobuping
2011-03-07 · TA获得超过340个赞
知道小有建树答主
回答量:195
采纳率:0%
帮助的人:268万
展开全部
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "所有Txt文件|*.txt|所有文件|*.*"
OpenFileDialog1.Title = "数据文件"
Dim filename As String
filename = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
filename = OpenFileDialog1.FileName
End If
Dim StrInfo As String
Dim i As Integer
Dim ReadStream As New System.IO.StreamReader(filename, System.Text.Encoding.Default)
If ReadStream IsNot Nothing Then
Do Until ReadStream.EndOfStream
StrInfo = ReadStream.ReadLine()
Dim a() As String = StrInfo.Split("-")
ListView1.Items.Add(a(0))
ListView1.Items(i).SubItems.Add(a(1))
i = i + 1
Loop
ReadStream.Close()
End If
End Sub
fufknp
2011-03-05 · TA获得超过397个赞
知道小有建树答主
回答量:463
采纳率:0%
帮助的人:0
展开全部
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式