多关键字查询 问题 我也问过类似的问题楼主参考一下吧http://community.csdn.net/Expert/topic/5268/5268677.xml?temp=4.540652E-02 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你个简单的例子string str = "我爱你老虎油";int i = System.Text.RegularExpressions.Regex.Matches(str,"我爱你").Count;//i即是我爱你在文章中出现的次数 这段代码你可以参考一下呵://分行搜索private void MenuItemSearchLine_Click(object sender, EventArgs e) { string[] strsRegs = new string[100]; char[] n = { '\n' }; if (TextBox.Text.Length != 0) //TextBox.Text是显示文章的地方 { strsRegs = AcceptStr.Split(n); //AcceptStr是你要搜索的关键字 FileStream file = new FileStream(filename, FileMode.Open); //filename是你要搜索的文章 StreamReader sr = new StreamReader(file, ansi); Dictionary<string, int> key = new Dictionary<string, int>(); //记录关键字和它的次数 int i = 1;//记录行数 string Strline; Strline = sr.ReadLine(); while (Strline != null) { foreach (string strReg in strsRegs) { if (!strReg.Equals("")) { key.Add(strReg, 0); Regex regex = new Regex(strReg); MatchCollection mc = regex.Matches(Strline); if (mc.Count > 0) { for (int j = 0; j < mc.Count; j++) { key[strReg]++; // } } richTextBoxResult.Text += "关键字:" + strReg + "在第" + i + "行出现" + key[strReg] + "次。\n"; } } Strline = sr.ReadLine(); i++; key.Clear(); } sr.Close(); } } 改变Label的text属性时发生滞缓现象. 怎样在winform下做一个类似IE7 的在新选项卡中打开链接 c# 调试 C写的 dll 的问题 找一个工具。 \u5c0f这种编码是什么,怎么转换为中文? 求js翻译成c#代码 获取硬盘容量—— 关于timer+progressbar控件 那里可以下到april后的MSDN? 谁有VS2003的下载地址呀?高分回报!! 请问这个问题怎么解决呀!(急) 分段读txt
int i = System.Text.RegularExpressions.Regex.Matches(str,"我爱你").Count;
//i即是我爱你在文章中出现的次数
private void MenuItemSearchLine_Click(object sender, EventArgs e)
{
string[] strsRegs = new string[100];
char[] n = { '\n' }; if (TextBox.Text.Length != 0) //TextBox.Text是显示文章的地方
{
strsRegs = AcceptStr.Split(n); //AcceptStr是你要搜索的关键字 FileStream file = new FileStream(filename, FileMode.Open); //filename是你要搜索的文章
StreamReader sr = new StreamReader(file, ansi); Dictionary<string, int> key = new Dictionary<string, int>(); //记录关键字和它的次数
int i = 1;//记录行数 string Strline;
Strline = sr.ReadLine();
while (Strline != null)
{
foreach (string strReg in strsRegs)
{
if (!strReg.Equals(""))
{
key.Add(strReg, 0); Regex regex = new Regex(strReg);
MatchCollection mc = regex.Matches(Strline);
if (mc.Count > 0)
{
for (int j = 0; j < mc.Count; j++)
{
key[strReg]++; //
}
}
richTextBoxResult.Text += "关键字:" + strReg + "在第" + i + "行出现" + key[strReg] + "次。\n";
}
}
Strline = sr.ReadLine();
i++;
key.Clear();
}
sr.Close();
}
}