public void ReplaceString(string TargetString, string NewString)
{
string FileSrc = System.Web.HttpContext.Current.Server.MapPath("../admin/TextFile1.txt");
if (File.Exists(FileSrc))
{
StreamReader sr = File.OpenText(FileSrc);
string srrow = null;
//读取文件所有的内容
srrow = sr.ReadToEnd();
if (srrow.IndexOf(TargetString) != -1)
{
//找到要找的字符串
var a = srrow.IndexOf(TargetString);
//要找的字符串后第一个"位置
var b = srrow.IndexOf(""", a);
//要找的字符串后第二个"位置
var c = srrow.IndexOf(""", b + 1);
//第一个"及之前的字符串
string subtop = srrow.Substring(0, b + 1);
//第二个"之后的字符串
string subbottom = srrow.Substring(c);
//拼接
NewString = subtop + NewString + subbottom;
//Response.Write(sub);
}
sr.Close();
//写入
StreamWriter sw = new StreamWriter(FileSrc, false);
sw.WriteLine(NewString);
sw.Close();
}