[C#] 纯文本查看 复制代码 private void del()
{
string num = "";
string str = "";
bool yesorno;
for (int i = 0; i < dataGridView2.RowCount; i++)
{
yesorno = false;
toolStripStatusLabel10.Text = (Convert.ToInt32(toolStripStatusLabel10.Text) + 1).ToString();
num = dataGridView2.Rows[i].Cells[0].Value.ToString();
num = "^" + num + ".*?$";
Regex r = new Regex(num, RegexOptions.Multiline);// 定义一个Regex对象实例
for (int n = 0; n < dataGridView1.RowCount; n++)
{
StreamReader SReader = new StreamReader(dataGridView1.Rows[n].Cells[0].Value + "\\" + dataGridView1.Rows[n].Cells[1].Value, Encoding.GetEncoding("gb2312"));
str = SReader.ReadToEnd();
SReader.Close();
Match m = r.Match(str);
if (m.Success)
{
dataGridView2.Rows[i].Cells[1].Value = "找到了:" + m.Value;
yesorno = true;
str = str.Replace(m.Value, "");
dataGridView2.Rows[i].Cells[1].Value = "删除了:" + m.Value;
FileStream fs1 = new FileStream(dataGridView1.Rows[n].Cells[0].Value + "\\" + dataGridView1.Rows[n].Cells[1].Value, FileMode.Create, FileAccess.Write);//创建写入文件
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(str, Encoding.GetEncoding("gb2312"));//开始写入值
str = "";
sw.Close();
fs1.Close();
toolStripStatusLabel12.Text = (Convert.ToInt32(toolStripStatusLabel12.Text) + 1).ToString();
break; //跳出for循环
}
}
if (yesorno == false)
{
dataGridView2.Rows[i].Cells[1].Value = "未找到:" + dataGridView2.Rows[i].Cells[0].Value.ToString();
toolStripStatusLabel14.Text = (Convert.ToInt32(toolStripStatusLabel14.Text) + 1).ToString();
}
}
}
换了gb2312也不行
|