public FileSpecs GetSpecsFromStringFile(string file) { file = Regex.Replace(file, "[^a-zA-Z0-9 ]+", "", RegexOptions.Compiled); string newinfo = file.ToString(); string[] words = newinfo.Split(' '); for (int i = 0; i < words.Length; i++) { words[i] = words[i].Trim(); } //Do the counts (could use map reduce) foreach (string current in words) { if (WordCount.ContainsKey(current)) { int val = 0; if (WordCount.TryGetValue(current, out val)) { WordCount[current] = val + 1; } } else { if (current != "") { WordCount.TryAdd(current, 1); } } } return(this); }
public void CountWords() { //creates dictionary <string, int> to store words and their counts foreach (var word in Words) { if (!WordCount.ContainsKey(word.ToString().Trim())) { WordCount.Add(word, 1); } else { WordCount[word] += 1; } } }