找到你要的答案

Q:How to check if a dictionary word is a part of a user input in vb?

Q:如何检查,如果一个单词是VB用户输入的一部分吗?

I've coded a password analyser for a school project. I want it to be able to test if their password contains a dictionary word in any place. For example, kdghdcheesegjgjd would still be flagged because it contains cheese. Would I need to find a file containing a list of all dictionary words, or is their such a built-in function?

Thanks.

我为学校的项目编写了密码分析器。我希望它能够测试他们的密码是否包含任何地方的字典字。例如,kdghdcheesegjgjd仍然会被因为它包含奶酪。我需要找到一个包含所有字典单词列表的文件,还是它们的内置函数?

谢谢.

answer1: 回答1:

Most languages don't have any (human language) dictionaries built into them. You will need to find/make your own and have the program read from that file.

A personal tip is to make your own very short one for testing purposes (say 5 words) to see that the program reads and interprets the file properly.

大多数语言中没有任何(人类语言)词典。您将需要找到/自己做,并从该文件读取程序。

一个个人的提示是让你自己很短的测试目的(说5个字),以查看程序读取和解释文件正确。

answer2: 回答2:

As stated by @Jonas Olsson, there is no built-in dictionary in VB. You need to create them on your own. And making it is fairly easy, but I'll show easier way to solve your problem. First make a text file containing all the words you want your program to check if it contains that word. Then save it somewhere else, for the sake of my example, I'll create a text file containing the word "cheese". So:

Dim myFile As String = "D:\test.txt" //Location of my txt file

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

    Dim item() As String = File.ReadAllLines(myFile) //Reads whatever your txt file contains

    //compares every line in your to text file to the password field
    For Each line As String In item 
        If txtPassword.Text.Contains(line) Then
            MessageBox.Show("Invalid password!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    Next
End Sub

Hope that helps! Or atleast it gave you an idea :))

由@ Jonas Olsson说,有VB没有内置词典。你需要自己创造。让它变得相当容易,但我会用更简单的方法来解决你的问题。首先制作一个文本文件,包含你想要你的程序的所有单词,以检查它是否包含该单词。然后把它保存在别的地方,为了我的例子,我会创建一个包含“奶酪”这个单词的文本文件。所以:

Dim myFile As String = "D:\test.txt" //Location of my txt file

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

    Dim item() As String = File.ReadAllLines(myFile) //Reads whatever your txt file contains

    //compares every line in your to text file to the password field
    For Each line As String In item 
        If txtPassword.Text.Contains(line) Then
            MessageBox.Show("Invalid password!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    Next
End Sub

希望帮助!或者至少它给你一个想法:))

answer3: 回答3:

You will have to find your own dictionary somewhere. I've used the The Gutenberg Webster's Unabridged Dictionary in the past myself because it's public domain. However, it is in a pretty raw form, and you'll likely have to do a lot of processing on it to get it in a shape that is usable to you.

There are likely other public domain or "open sourced" wordlists somewhere that you can use. I suggest a google search for "public domain english word list" or "free english word list" or similar searches. Then it's just a matter of reading in the file and doing your processing against it.

你必须在某处找你自己的字典。我用Gutenberg Webster的大词典在过去的自己,因为它是公共领域。然而,它是在一个相当原始的形式,你可能会做很多的处理,使其在一个形状,可供您使用。

有可能其他公共领域或“开源”生词的地方,你可以使用。我建议谷歌搜索“公共领域英语单词列表”或“免费英语单词列表”或类似的搜索。然后,它只是一个问题,在文件中读取和处理你对它。

vb.net  dictionary