搜索数据库中的字符串

时间:2016-04-26 00:51:16

标签: vb.net string search

假设我有file.txt file.txt包含:

banana peach orange
black white yellow
car train airplane

我想在vb.net中包含以下代码:

Button1 (Search button)
Textbox1 (What you want to search)
Listview1 (Shows results)

基本上,当我在Textbox1中键入桃子并按下Button1上的搜索时,我希望它在Listview1中显示香蕉桃橙色。 如果有人能帮助我,我将非常感激,因为我没有任何vb.net经验。

亲切的问候, Eric Sturdivant

1 个答案:

答案 0 :(得分:0)

Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
For Each line In File.ReadAllLines("example.txt")
If line.Contains(TextBox1.Text)
    Dim leftPart As String = line.Split(" ")(0)
    Dim middle As String = line.Split(" ")(1)
    Dim right As String = line.Split(" ")(2)
    Dim newItem As New ListViewItem(leftPart)
    newItem.SubItems.Add(middle)
    newItem.SubItems.Add(right)
    ListView1.Items.Add(newItem)
End If
Next
End Sub

至少应该让你知道从现在开始的去哪里。