Hello, I have wrote a program that reads in words from a text file stored on my hard drive and converts each word into a corresponding code depending on the combination of letters of each word. Now I have two text files that I want to code, one is the first 228 words of a dictionary, the second is full dictionary of 79769 words.
Once I have converted each word to its related code I then want to remove any zero's and replace any successive numbers with one digit for example, 06558 would become 658. I have wrote the code below and it works fine for the file that is 228 words long, but when I try and read in the full dictionary and change my array sizes, I run the program and nothing happens, the complier just presents me with a black screen whereas before it printed out each word and its corresponding code.
At first I thought ok maybe it takes a while to process 80000 words but I have left the program running for half an hour with nothing but a flashing cursor.
Is there a limit on the amount of string processing a string builder can do? Does anyone know where i'm going wrong in my code?
string word = string.Empty, strOut = string.Empty;
StreamReader sr = new StreamReader("c:/dictionary.txt");
string line;
string[] dictionary = new string[228];//79769 or 228
int q = 0;
while ((line = sr.ReadLine()) != null)
{
dictionary[q] = line;
q++;
}
StringBuilder builder = new StringBuilder();
foreach (string s in dictionary)
{
word = s;
foreach (char c in word)
{
switch (c)
{
case 'r':
strOut = strOut + "6";
break;
case 'l':
strOut = strOut + "4";
break;
case 'm':
case 'n':
strOut = strOut + "5";
break;
case 'd':
case 't':
strOut = strOut + "3";
break;
case 'b':
case 'f':
case 'p':
case 'v':
strOut = strOut + "1";
break;
case 'c':
case 'g':
case 'j':
case 'k':
case 'q':
case 's':
case 'x':
case 'z':
strOut = strOut + "2";
break;
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'h':
case 'y':
case 'w':
strOut = strOut + "0";
break;
}
}
builder.Append(strOut);
builder.AppendLine();
builder.Replace("0", "");
builder.Replace("11", "1");
builder.Replace("22", "2");
builder.Replace("33", "3");
builder.Replace("44", "4");
builder.Replace("55", "5");
builder.Replace("66", "6");
strOut = String.Empty;
}