c#文本文件中替换字符串 10
有文本文件a.txt里面内容:seta="a"'bianliangasetb="b"'bianliangbsetfind="find"'bianliangfindsetx...
有文本文件a.txt
里面内容:
set a="a" 'bianliang a
set b="b" 'bianliang b
set find = "find" 'bianliang find
set xxx="xxxxxxxxx" 'bianliang xxx
set yy="yyyyyy" 'bianliang yy
set ......有好多这样的行
现在要找到set find = "find" 'bianliang find
换成setAndReplace newfind = "newfind" 'bianliang newfind
再找到set yy="yyyyyy" 'bianliang yy
换成setAndReplace yy= "yy" 'bianliang yy
这样怎么弄?
C#代码怎么写? 展开
里面内容:
set a="a" 'bianliang a
set b="b" 'bianliang b
set find = "find" 'bianliang find
set xxx="xxxxxxxxx" 'bianliang xxx
set yy="yyyyyy" 'bianliang yy
set ......有好多这样的行
现在要找到set find = "find" 'bianliang find
换成setAndReplace newfind = "newfind" 'bianliang newfind
再找到set yy="yyyyyy" 'bianliang yy
换成setAndReplace yy= "yy" 'bianliang yy
这样怎么弄?
C#代码怎么写? 展开
3个回答
展开全部
string text = string.Empty;
using (FileStream fs = new FileStream("a.txt", FileMode.Open, FileAccess.Read))
{
using (StreamReader sr = new StreamReader(fs))
{
text = sr.ReadToEnd();
text=text.Replace("xxxx", "yyyyy");
}
}
using(FileStream fs = new FileStream("a.txt", FileMode.Create, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(text);
}
}
展开全部
如果你是用程序替换的话,就用replcace方法,如果不是那就用VS打开这个文本文件,按Ctrl+F键,你自己试试吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询