我需要帮助比较资源中的文本文件中的字符串行与文本框的字符串行(vb.net)

时间:2015-02-06 00:34:26

标签: database vb.net string resources compare

我现在已经找到了解决之前问题的方法,但我现在需要更多的帮助。我想比较用户输入的字符串和文本文件中找到的字符串列表。我成功了,但现在我想做相同但不是文件系统中的文本文件,我希望它在应用程序资源中。我确实找到了一种方法来读取资源文本文件,并通过使其在消息框中输出内容来确认它,但现在当我替换普通的流读取器代码,用于读取应用程序所在的资源文件并且不执行任何操作,而不是给出一个消息框,确认它找到了像文件流代码中的字符串匹配。这就是我现在所拥有的:

Imports System.IO
Imports System.Resources
Imports System.Reflection

Public Class Form1


    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click


'The original stream reader code bit that worked:Dim Lines As String = IO.File.ReadAllLines("1.txt")

        Dim Lines As String = My.Resources.ResourceManager.GetObject("_1")

'Above is the new resource reader code that is in place of old stream reader IO code


For Each line As String In Lines 'Every time the program reads a new line from the textfile database


 If line = TextBox1.Text Then'if a line from the text file 'matches that with the textbox input
                MsgBox("works")'user confirmation it matched
                GoTo A'jumps to "A:" to end the "for" loop
            Else

            End If
        Next
A:'where the jump leads to

    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

您的 For Each 语句有效地将拆分为单个字符,而不是文本行。你需要使用类似的东西:

Dim actualLines() As String = lines.Replace(vbCrLf, vbCr).Split(vbCr)
        For Each line As String In actualLines
...