C#编程 如何统计txt或者word文档中某个字出现的次数,求大神指导,稍微具体点,谢谢
2013-11-16
展开全部
假如是xp系统下桌面的a.txt文档,那么:
try
{
String path = "C:\\Documents and Settings\\Administrator\\桌面\\a.txt";
StreamReader sr = new StreamReader(path);
String line;//接收字节流
String str = "";//接收txt文档内容的变量
while ((line = sr.ReadLine()) != null)
{
str += line;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
int count = 0;//计数器
string search = "的"; //要查的字符串
for (int i = 0; i < str.Length-search.Length; i++)
{
if (str.Substring(i, search.Length) == search)
{
count++;
}
}
Console.WriteLine("在a.txt中,“的”出现了"+ count +"次。");
try
{
String path = "C:\\Documents and Settings\\Administrator\\桌面\\a.txt";
StreamReader sr = new StreamReader(path);
String line;//接收字节流
String str = "";//接收txt文档内容的变量
while ((line = sr.ReadLine()) != null)
{
str += line;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
int count = 0;//计数器
string search = "的"; //要查的字符串
for (int i = 0; i < str.Length-search.Length; i++)
{
if (str.Substring(i, search.Length) == search)
{
count++;
}
}
Console.WriteLine("在a.txt中,“的”出现了"+ count +"次。");
2013-11-16
展开全部
此贴不红,天理难容!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询