C# Check spelling of a word.

hey all. I’ve been on google all day trying to find out how to check the spelling of a word in game. obviously getting nowhere, that’s why i’m here. I’n my game you make up a word by selecting different letters. when you think you have a word you click the ‘check word’ button and the word gets checked to find out if its an actual word in the dictionary. I’ve downloaded a text document that has 35000 words. this is as far as i can get on the information that’s available. if anyone could help i’d really appreciate it. thank you.

You’ll definitely need a tree for this or something like it, i would sugest separating them into alphabetic order for first and second letter, this will leave you with a search of +or- 79 words.

You can use a Dictionary<char, Dictionary<char, List<string>>>, while reading your document look at the first letter of it and set into the first dictionary as key, than in this dictionary look at the second letter and set it as the key and the accutual word add as value to the List, the code would be something like this:

private Dictionary<char, Dictionary<char, List<string>>> _wordsTree = new Dictionary<char, Dictionary<char, List<string>>>();

public void Start()
    {
        //This will create a tree like thing.

        foreach(char __letter in _alphabet)
        {
            _wordsTree.Add(__letter, new Dictionary<char, List<string>>());
        }

        foreach(char __nodeKey in _wordsTree.Keys)
        {
            foreach (char __letter in _alphabet)
            {
                _wordsTree[__nodeKey].Add(__letter, new List<string>());
            }
        }

        //Then you'll have to do read your document word by word and add to the tree:

        //This foreach is just a fake ideia of code, i don't remmeber how to read words from
        // a document just look on google shouldn't be hard to find.
        foreach(string __word in wordsDocument.GetWord())
        {
            //This is accutualy how you would add something to the tree.
            _wordsTree[__word[0]][__word[1]].Add(__word); 
        }

        //Then to see if the word exist just do:

        string __playerWord = "potato"; //This is the word the player entered.

        _wordsTree[__playerWord[0]][__playerWord[1]].Contains(__playerWord);
    }