對an earlier question的回答進行跟進。最小化LINQ字符串令牌計數器
有沒有辦法進一步減少這個,避免外掛String.Split
電話?目標是一個關聯容器{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))
});
爲什麼你不想使用'string.Split'來標記? – 2010-10-28 00:50:12
@Kirk - 這不是我想要避開斯普利特,我只是尋找更優雅和高效(如果可能的話)公式。 – 2010-10-28 01:54:29