循环遍历 VB.NET 中的文本文件的行 [英] Loop through the lines of a text file in VB.NET

查看:17
本文介绍了循环遍历 VB.NET 中的文本文件的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,里面有几行文本.

I have a text file with some lines of text in it.

我想遍历每一行,直到找到我想要的项目*,然后以标签的形式将其显示在屏幕上.

I want to loop through each line until an item that I want is found*, then display it on the screen, in the form of a label.

*我正在通过文本框搜索该项目.

*I am searching for the item through a textbox.

也就是说,在 sudo 中:

That is, in 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

推荐答案

您可以使用 File.ReadLines 方法 以便在整个文件中迭代,一次一行.这是一个简单的例子:

You can use the File.ReadLines Method in order to iterate throughout your file, one line at a time. Here is a simple example:

    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

这篇关于循环遍历 VB.NET 中的文本文件的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆