Vb.net Visual Basic-从字符串中选择值并将其定义为

Vb.net Visual Basic-从字符串中选择值并将其定义为,vb.net,Vb.net,我有一个txt的日志文件,里面是字符串信息。一个字符串如下所示: 49000 120614 12334480 12 32 2 90 90 90 321 384 2 345 873 890 空格之间的每个值表示特定的内容(例如,第二行“120614”是日期“2014年6月12日”),我正在编写一个程序,将txt文件加载到其中,然后当我单击某个按钮时,它将获取该字符串并将所有值放入特定的文本框中,例如,“date=12 06 2014”。我一直在研究如何找到某一行并将该行及其内容声明为某物,但我没有

我有一个txt的日志文件,里面是字符串信息。一个字符串如下所示:

49000 120614 12334480 12 32 2 90 90 90 321 384 2 345 873 890

空格之间的每个值表示特定的内容(例如,第二行“120614”是日期“2014年6月12日”),我正在编写一个程序,将txt文件加载到其中,然后当我单击某个按钮时,它将获取该字符串并将所有值放入特定的文本框中,例如,“date=12 06 2014”。我一直在研究如何找到某一行并将该行及其内容声明为某物,但我没有找到答案!!我正在使用VisualBasic来编写它,我真的需要帮助来确定方向,stramreader能做到这一点吗??我在寻找什么功能

这是我加载文件的代码。。以防万一

  Public Class Form1

  Private Sub browsebtn1_Click(sender As Object, e As EventArgs) Handles browsebtn1.Click
    Dim filedialog As New OpenFileDialog 'openfiledialog1 is now filedialog'
    filedialog.Filter = "Text Document|*.txt" 'filter the openfiledialogs file extension to txt only'
    filedialog.Title = "Select Bosvark Log File.." 'openfiledialog title'
    If filedialog.ShowDialog = Windows.Forms.DialogResult.OK Then 'if the file is chosen then..'
        filepath1.Text = filedialog.FileName 'filepath1 text is file path of selected file'
        RichTextBox1.LoadFile(filepath1.Text, RichTextBoxStreamType.PlainText) 'richtextbox1 retrieves the file path and displays the document'
    End If
    End Sub

    Private Sub convertbtn_Click(sender As Object, e As EventArgs) Handles convertbtn.Click
    If RichTextBox1.Text = "" Then
        MessageBox.Show("Please load a file first!") 'If user doesnt load a file, give them an error message.'
    End If
     End Sub

    Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles     RichTextBox1.TextChanged
    If RichTextBox1.Text = "" Then
        RichTextBox1.Visible = False 'If there is no file loaded, The textbox will not appear.'
        Else
            RichTextBox1.Visible = True 'if the file is loaded, textbox will appear.'
        End If
    End Sub
End Class

您可以将文件内容加载到字符串变量(如果文件不太大)

您可以将所有数据拆分为每行一个数组

Dim strLine() As String
strLine = Split(strData)
您可以在所有行上循环以在所有行上执行某些操作

Dim lngLine As Long
For lngLine = 0 To UBound(strLine)
  'do action
Next lngLine
或者只在一个特定行上执行一个操作:

dim strField() as String
'split line into array separated per spaces
strField = Split(strLine(lngLine), " ")

谢谢,我会试试的。我所需要的只是一些参考资料,所以你的回答非常有用。
dim strField() as String
'split line into array separated per spaces
strField = Split(strLine(lngLine), " ")