在VB.NET中循环浏览文本文件的各行 [英] Loop through the lines of a text file in VB.NET

查看:111
本文介绍了在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

推荐答案

您可以使用

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天全站免登陆