Omn*_*pus 3 vb.net text loops visual-studio-2008
我有一个文本文件,其中包含一些文本行.
我想遍历每一行,直到找到我想要的项目*,然后以标签的形式将其显示在屏幕上.
*我正在通过文本框搜索该项目.
也就是说,在sudo中:
For i = 0 To number of lines in text file
If txtsearch.text = row(i).text Then
lbl1.text = row(i).text
Next i
Run Code Online (Sandbox Code Playgroud)
您可以使用File.ReadLines方法迭代整个文件,一次一行.这是一个简单的例子:
Dim Term As String = "Your term"
For Each Line As String In File.ReadLines("Your file path")
If Line.Contains(Term) = True Then
' Do something...Print the line
Exit For
End If
Next
Run Code Online (Sandbox Code Playgroud)