我有一个长字符串,如下所示。当它找到一些关键字时,我想替换一些字符(.abc_ or .ABC_)
。当系统逐行读取时,如果找到关键字,则将替换前面的单词变成"john"
insert into material.abc_Inventory; Delete * from table A; ....
insert into job.ABC_Inventory; Show select .....; ....
变成
insert into john.ABC_Inventory; Delete * from table A;
insert into john.ABC_Inventory; Show select .....;
下面是我的代码。
string output = string.Empty;
using (StringReader reader = new StringReader(content))
{
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Contains(".ABC_"))
line.Replace(" word in front of the keyword" + line.Substring(line.IndexOf(".ABC_")), " john" + line.Substring(line.IndexOf(".ABC_")));
output += whole line of edited code;
else if (line.Contains(".abc_"))
line.Replace(" word in front of the keyword" + line.Substring(line.IndexOf(".abc_")), " john" + line.Substring(line.IndexOf(".abc_")));
output += whole line of edited code;
else
output += line.ToString();
}
}
我无法在关键字前面获得材料或工作一词。