I have a dictionary of random strings (key), and their ASCII sum(value). From this, I want to create a new dictionary of distinct ASCII sums, and a List of all strings that match the ASCII sum.
I have attempted making a List of the unique ASCII sums and accessing my dictionary with that.
private void LoadFile_Click(object sender, EventArgs e)
{
//locate file with OpenFileDialog
OpenFileDialog of = new OpenFileDialog(); //create new openfile dialog
//save file path
if (of.ShowDialog() == DialogResult.OK)
{
path = of.FileName;
label1.Text = path.ToString();
}
//using streamreader and read to end, load entire contents
//of file into a string
using (StreamReader sr = new StreamReader(path))
{
_text = sr.ReadToEnd();
}
//seperate massive string by newline or carriage returns
string[] words = _text.Split('\r', '\n');
//tolist this array of strings
List<string> Word = words.ToList();
//remove all white spaces or empty lines
Word.RemoveAll(w => w == "");
//produce a Dictionary keyed by each line chars
//value is the ASCII sum of the chars
Dictionary<string, int> dict = new Dictionary<string, int>();
dict = Word.ToDictionary(key => key, value => value.Sum(x => x));
//key is the sum, value is all the strings that have that sum
Dictionary<int, List<string>> _Distinct = new Dictionary<int, List<string>>();
List<int> uniqueSums = new List<int>();
uniqueSums = dict.Values.Distinct().ToList();
foreach (int item in uniqueSums)
{
dict.Where(x => x.Value == item).ToList();
}
Console.Read();
}