【发布时间】:2011-08-19 08:47:04
【问题描述】:
标题说明一切..
搜索了谷歌和 Stackoverflow,没有找到类似的东西..
【问题讨论】:
标题说明一切..
搜索了谷歌和 Stackoverflow,没有找到类似的东西..
【问题讨论】:
对于.txt 文件,您可以使用正则表达式\b\w+\b。它将匹配所有出现的单词,例如:
var count = Regex.Matches(input, @"\b\w+\b").Count;
计算字母:
int count = input.Count(char.IsLetter);
【讨论】:
static void Main()
{
const string t1 = "To be or not to be, that is the question.";
Console.WriteLine(WordCounting.CountWords1(t1));
Console.WriteLine(WordCounting.CountWords2(t1));
const string t2 = "Mary had a little lamb.";
Console.WriteLine(WordCounting.CountWords1(t2));
Console.WriteLine(WordCounting.CountWords2(t2));
}
更多的是here
【讨论】:
从 rtf 获取文本 - Get plain text from an RTF text
计算文本中的单词 - http://www.dotnetperls.com/word-count
【讨论】: