我不知道为什么会这样,但我有一些代码在表单上的文本框中搜索字符串:
Dim strLines() As String = strText.Split(CChar(Environment.NewLine))
Dim i As Integer
Dim strRet As String = ""
For j As Integer = 0 To strLines.Length - 1
i = strLines(j).IndexOf("&&&")
If i >= 0 Then
strRet &= strLines(j).Substring(i + 3) & Environment.NewLine
End If
If strRet.Length > 0 Then
If txtConsole.TextLength > 0 Then
Call ClearCon()
End If
rtxtDefinition.Text = ""
txtWrdDefn.Text = strRet
Dim sourceString As String = New System.Net.WebClient().DownloadString("http://api.urbandictionary.com/v0/define?term=" & strRet)
rtxtDefinition.Text = sourceString
毕竟这只是处理它并且工作正常。问题是,这会从你无法清除控制台的游戏中获取信息,因此它会不断地搜索它并保持返回相同的定义。有没有办法防止这种情况发生,因为无法清除游戏机?
答案 0 :(得分:0)
正如我的评论所指出的,这里有代码:
Public Class Form1
Dim LastSearchEnd As Integer = 0 'This variable keeps it's value, it's initialized with the value 0 on program start
Private Sub SearchStuff()
Dim strLines() As String = Strings.Split(TextBox1.Text, Environment.NewLine) 'Split the text into lines
For i = LastSearchEnd To strLines.Count - 1 'Start at the value you kept
If strLines(i).Contains("&&&") Then 'Found the value
MsgBox("FOUND IT!!")
LastSearchEnd = i + 1 'We actually keep i+1 because we don't want to search the same line twice
Exit For
End If
Next
End Sub
End Class
对于我认为你想要的东西,这是一个细分的例子。