Followup on answer to an earlier question.
Is there a way to further reduce this, avoiding the external String.Split
call? The goal is an associative container of {token, count}
.
string src = "for each character in the string, take the rest of the " +
"string starting from that character " +
"as a substring; count it if it starts with the target string";
string[] target = src.Split(new char[] { ' ' });
var results = target.GroupBy(t => new
{
str = t,
count = target.Count(sub => sub.Equals(t))
});
See Question&Answers more detail:os