我正在尝试创建一些代码,以在字典中的单词中搜索单词,但是在找到第一个单词后,它再次遍历循环时会覆盖自身。
我尝试将所有存储有值的变量放入数组中,但是当我这样做时,我得到了对象引用错误的提示。
For x = 0 To 58110
For i = 0 To 58110
mypos(i) = 1
mypos(i) = InStr(password, dictionary_english(i))
If mypos(i) > 0 Then
word1 = dictionary_english(i)
If Not String.IsNullOrEmpty(word1) Then found_word = True
MsgBox(mypos(i))
MsgBox(word1)
If found_word = True Then
mylengthpassword = Len(password)
mylengthdictionary = Len(word1)
Dim secstr As String
Dim finalstr As String
Dim befstr As String
secstr = password.Substring(mypos(i) - 1)
finalstr = secstr.Substring(mylengthdictionary)
befstr = Mid(password, 1, mypos(i) - 1)
MsgBox(word1)
MsgBox(secstr)
MsgBox(word1)
MsgBox(password)
MsgBox(befstr)
End If
End If
Next
Next
我想要的是将所有已建立的单词存储在某种形式的列表或数组中,并在其中找到它们的位置。
答案 0 :(得分:0)
我不太了解您在做什么支票。这是我所能接近的。英文字典也可以很容易地成为数组。
Private dictionary_english As New List(Of String)
Private Function CheckStrength(password As String) As String
For Each word In dictionary_english
If word.Contains(password) Then
Return "Password contained in Dictionary"
'The function will stop checking as soon as it finds a match
End If
Next
Return "Password is not found in dictionary"
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim message = CheckStrength(txtPassword.Text)
MessageBox.Show(message)
End Sub