2
我有2列CSV文件: 11111,0001.jpg 22222,0002.jpg 33333,0003.jpg显示特定CSV字段信息在Visual Basic列表框中
我建立一个Visual Basic Windows窗体在Visual Studio 2013应用程序。该应用程序将在一边有一个文本框和浏览按钮。文本框显示使用浏览按钮选择的文件位置。在应用程序的另一边是两个列表框。我有listbox1显示我的csv文件的第一列。我想第二个列表框listbox2只显示我csv文件第二列中的最后4个字符。这是我的代码到目前为止。我不知道如何选择字段中的某些字符。
Public Class Form1
Dim streamer As IO.StreamReader
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
ListBox2.Items.Clear()
Dim ofd1 As New OpenFileDialog
If ofd1.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = ofd1.FileName
End If
streamer = IO.File.OpenText(ofd1.FileName)
Label3.Text = IO.File.ReadAllLines(ofd1.FileName).Length
Dim MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(ofd1.FileName)
MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.Delimiters = New String() {","}
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
ListBox1.Items.Add(currentRow(0))
ListBox2.Items.Add(currentRow(1))
Catch ex As Exception
End Try
End While
End Sub