Skip to content

Instantly share code, notes, and snippets.

@manifoldhiker
Created February 21, 2017 08:36
Show Gist options
  • Save manifoldhiker/2a5a4a35dc7f2d8368653c9a4dc7ade0 to your computer and use it in GitHub Desktop.
Save manifoldhiker/2a5a4a35dc7f2d8368653c9a4dc7ade0 to your computer and use it in GitHub Desktop.
private void loadDictionary()
{
try
{
dictionary = new Dictionary<string, List<string>>(); // **field to hold your data. Could be List<> or somethin
using (StreamReader sr = new StreamReader("E:\\Programming\\answer_database.txt")) // **Opening file, create reader
{
//**in my dictionary words were separated by "\"
string[] arr = sr.ReadLine().Split('\\'); // **read first line
while (arr.Length != 0) // **while we have smth to read
{
arr = sr.ReadLine().Split('\\'); //**read next line (first was misfourtunantly skipped =( )
//**LOGIK GOES HERE
if (dictionary.ContainsKey(arr[0]))
{
dictionary[arr[0]].Add(arr[1]);
continue;
}
dictionary.Add(arr[0], new List<string>() { arr[1] });
//**
}
}
}
catch (Exception e)
{
Console.WriteLine("Loaded");
}
Console.WriteLine("Loaded");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment