Search code examples
vb.netanagram

How can I check if a string given is a real word?


I am making a program that solves anagrams in Visual Basic. How can I check if a string given by the anagram solver is a real word? I know I will have to access some sort of dictionary but I have no idea how to do this?

I need a function that checks the word to return a true/false boolean value. Is this possible?

I'm using Visual Basic in Microsoft's VS2015.


Solution

  • Hunspell is pretty easy to use.

    • Install the .net-library through Nuget (open your project in Visual Studio, then > Extras > Nuget-Package-Manager -> Console, type Install-Package NHunspell)
    • Download the .aiff and .dic files, see the dictionaries link on the Hunspell project page. Include these files in your project or use absolute paths.

    Sample Code:

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        Using h As New NHunspell.Hunspell(
            "...path ...\en_US.aff",
            "...path ...\en_US.dic")
            Me.TextBox1.BackColor = If(h.Spell(Me.TextBox1.Text),
                Color.PaleGreen, Color.PeachPuff)
        End Using
    End Sub
    

    Hunspell

    .net library NHunspell

    NHunspell C# Code Samples