嗨,我正在尝试查找和替换字符串。问题是String.Replace
函数需要两个参数来表示旧值和新值。我需要类似的东西
(content, textBox1.Text, textBox1.Text)
我试过使用Regex
,但没有用
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "All Files|*.*|Images Files(*.jpeg)|*.jpeg";
//openFileDialog1.Multiselect = true;
DialogResult dr = openFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.GetEncoding("Windows-1254"));
string content = sr.ReadToEnd();
sr.Close();
content = Regex.Replace(content, textBox1.Text, textBox1.Text);
StreamWriter sw = new StreamWriter(content);
sw.Write(content);
sw.Close();
}
}