Divide and win. Divide your problem into many smaller tasks and solve each of them.
: .
, , . , , "", , , , , , , "" , "". , , ( ), - , , .
, . . :
StreamReader streamReader = new StreamReader(@"c:\survey.txt");
string source = streamReader.ReadToEnd();
, -. . , , "" "" , . ? , , :
char[] punctuation = new char[] {' ', '\n', '\r', '\t', '(', ')', '"'};
string[] tokens = source.ToLower().Split(punctuation, true);
. . , . , .. , .
ToLower? ToLowerInvariant? , ; . , ToLower canoncialize , . . - "-", - " ", , . ? .
: :
var firstPass = new Dictionary<string, int>();
foreach(string token in tokens)
{
if (!firstPass.ContainsKey(token))
firstPass[token] = 1;
else
++firstPass[token];
}
. , . , . , , - , . /, :
var groups = from pair in firstPass
group pair.Key by pair.Value;
, , . . , , :
var sorted = from group in groups
orderby group.Key
select group;
, :
foreach(var g in sorted.Take(100))
{
Console.WriteLine("Words with count {0}:", g.Key);
foreach(var w in g)
Console.WriteLine(w);
}
.
, , ? , . "" "" , . "" "" , . "" "" , , , - .
; , , .
, , - , . : , , .