C# - Checking Output against english dictionary

As the title states, I am writing a program that takes a bunch of random letters and turns them into english words. I have gotten the program to output every variation of the inputted letters, but its hard searching through them all for actual english words. How would I go about checking the output against an english dictionary? Any help would be appreciated!
10 answers Last reply Best Answer
More about checking output english dictionary
  1. First of all you need to store the dictionary somehow. There are a few ways you could do this ranging from a straightforward array to using a database. Probably the most efficient way would be to use some sort of tree structure. The top level nodes which each contain single letters of the alphabet; the second level nodes (up to 26 per first-level node) would contain a single letter which is a possible second letter for a word (so for 'a' there would probably be 26 second-level nodes, for 'q' only one or two), etc. To check a word against the dictionary you just check that the first letter is one of the first-level nodes, the second one of the second-level nodes for that first-level one, etc. That's probably the most efficient way of storing the dictionary for quick searches.

    Of course the biggest problem is inputting the dictionary initially....
  2. I'm not sure if this is at all doable, but just emptying my brain out on the page. Would it be possible to query a pre-existing database (such as's)? As ijack said, the initial creation of said dictionary would be a pain.
  3. I was thinking of a standalone solution, but if online checking is acceptable then this thread may contain a few ideas of interest.
  4. Ijack said:
    I was thinking of a standalone solution, but if online checking is acceptable then this thread may contain a few ideas of interest.

    I just didn't see the OP specify, so figured it was a viable solution :D
  5. thanks for the input. I got a text document with most if not all the english words listed. Can I search that using something like a StreamReader?
  6. Best answer
    I would read each line into a String (using StreamReader.ReadLine), or you could even read the whole file (using StreamReader.ReadToEnd) if it's not too big. Then split the String into words (using String.Split) at which point you can do the character-by-character comparison. An alternative would be to just read each character from the file (using StreamReader.Read) and create each word yourself. One thing that you need to be aware of is the possibility of end-of-line breaks (denoted by a hyphen); all depends upon what you know about the input file. In any case, actually extracting the individual words from the text file shouldn't be too difficult.
  7. each word is listed on a single line in the text file, should i use carriage return or line feed with string.split?
  8. If each word is on a single line then ReadLine should just read the word into a String. Exactly what you want!
  9. thanks ijack, i got it to work
  10. Best answer selected by jefe323.
Ask a new question

Read More

Programming C# Apps