我现在已经找到了以前问题的解决方案,但我现在需要更多帮助。我想将用户输入的字符串与文本文件中的字符串列表进行比较。我成功了,但现在我想做同样的事情,但我不希望文本文件在文件系统中,而是希望它在应用程序资源中。我确实找到了一种读取资源文本文件的方法,并通过让它在消息框中输出内容来确认它,但现在,当我用读取资源文件的代码替换普通的流读取器代码时,应用程序就在那里,什么也不做,而不是像在文件流代码中那样给出一个消息框来确认它找到了字符串匹配。这是我现在拥有的:
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
您的For Each语句有效地将行拆分为单个字符,而不是文本行。你需要使用类似的东西:
Dim actualLines() As String = lines.Replace(vbCrLf, vbCr).Split(vbCr)
For Each line As String In actualLines
...