vb.net读取固定格式txt文件
展开全部
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
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
展开全部
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 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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |