vb.net - 变量在循环时会覆盖自己
问题描述
我正在尝试创建一些代码,在字典中搜索单词以查找引用,但是在找到它的第一个单词后,它会在再次循环时覆盖自身。
我已经尝试将所有具有存储在其中的值的变量放入数组中,但是当我这样做时,我得到了对象引用错误的基调。
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
我想要的是将所有已建立的单词存储到某种列表或数组中,并在其中找到它们的位置。
解决方案
我无法完全了解你在做什么检查。这是我能来的最接近的地方。英语词典也可以很容易地成为一个数组。
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
推荐阅读
- python - 运行 bash 命令在 Python3 中复制粘贴文件是一个可靠的选择吗?
- database - 表格 - 转到下一页的按钮
- linux - 我可以在 shell 脚本的第一行省略“shebang”的完整路径吗?
- python - 关于 sum 函数的 Python 弃用警告
- python - ValueError:超出最大允许尺寸,AgglomerativeClustering fit_predict
- amazon-web-services - AWS Cloudformation 错误:由于递归导入而导致递归锁定
- wordpress - Elementor 插件无法在 localhost 上运行
- python - 消息未显示在管理 django 面板中
- symfony - 实体如何被持久化两次?
- django - Django 无法从 DetailView 更新另一个模型