Exemple #1
0
        private AllWords()
        {
            var url = "http://app.aspell.net/create?max_size=60&spelling=AU&max_variant=0&diacritic=strip&download=wordlist&encoding=utf-8&format=inline";

            System.Console.WriteLine($"Getting all English words from:\n{url}\nThis will take a little while...");

            WordLists = new Dictionary <int, List <string> >();
            for (int i = 3; i <= _maxLetters; i++)
            {
                WordLists.Add(i, new List <string>());
            }

            var enumerator = new System.Net.WebClient().DownloadString(url).Split("\n").GetEnumerator();

            for (int i = 0; i < 44; i++)
            {
                enumerator.MoveNext();
            }

            while (enumerator.MoveNext())
            {
                string word = enumerator.Current.ToString().Trim();

                if (word.Length < 3 || word.Contains("'") || char.IsUpper(word[1]))
                {
                    continue;
                }

                var letterCount = word.Length > _maxLetters ? _maxLetters : word.Length;

                WordLists[letterCount].Add(word.ToLower());
            }

            for (int i = 3; i <= _maxLetters; i++)
            {
                WordLists[i].Sort();
            }

            System.Console.WriteLine($"Completed the retrieval of all words!\n\n");
        }