有没有办法将文本文件导入vb.net中的datagridview
美好的一天,我将文本文件导入DataGridView,我想拥有这样的输出
|名称|仪表编号
0123RR Road 6 | Doe,John | 123ABC456789
文本文件看起来像是此
0123RR ROAD 6 DOE,JOHN 123ABC456789
地址的字符数量为25和10,从名称到仪表编号。
我的代码看起来像这样,
Dim lines() As String
Dim vals() As String
OpenFileDialog1.Filter = "TEXT FILE | *.txt |ALL FILES |*.*"
If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
lines = File.ReadAllLines(OpenFileDialog1.FileName)
For i As Integer = 12 To lines.Length - 1 Step +1
'Dim newlines As String = lines(i).Substring(25, 20)
vals = lines(i).ToString().Split(" "c, StringSplitOptions.RemoveEmptyEntries)
Dim row(vals.Length - 1) As String
For j As Integer = 0 To vals.Length - 1 Step 2
row(j) = vals(j).Trim()
Next j
dt.Rows.Add(row)
Next i
End If
谢谢
Good day, i am importing text file to datagridview and i want to have the output like this
LOT ADDRESS | NAME | METER NUMBER
0123RR ROAD 6 | DOE, JOHN | 123ABC456789
text file looks like this
0123RR ROAD 6 DOE, JOHN 123ABC456789
the character count from address to name is 25 and 10 from name to meter number.
my code looks like this
Dim lines() As String
Dim vals() As String
OpenFileDialog1.Filter = "TEXT FILE | *.txt |ALL FILES |*.*"
If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
lines = File.ReadAllLines(OpenFileDialog1.FileName)
For i As Integer = 12 To lines.Length - 1 Step +1
'Dim newlines As String = lines(i).Substring(25, 20)
vals = lines(i).ToString().Split(" "c, StringSplitOptions.RemoveEmptyEntries)
Dim row(vals.Length - 1) As String
For j As Integer = 0 To vals.Length - 1 Step 2
row(j) = vals(j).Trim()
Next j
dt.Rows.Add(row)
Next i
End If
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论