编辑字符串数组中的行并写入新数组c#
我是新的编码,我有一个批处理文件,我读入字符串数组,现在我正在寻找特定的词,然后我想编辑它们,并将所有数组行写入一个新的批处理文件 比如说 我的批处理文件是: 设置图像1=编辑字符串数组中的行并写入新数组c#,c#,C#,我是新的编码,我有一个批处理文件,我读入字符串数组,现在我正在寻找特定的词,然后我想编辑它们,并将所有数组行写入一个新的批处理文件 比如说 我的批处理文件是: 设置图像1= 设置图像2= 我想查找“set image1=”并将其编辑为“set image1=c:\1.jpg” 现在我不知道如何编辑它。您可以更新阵列。因为替换行-变量不会做任何事情,因为它是不可变的 string[] lines = System.IO.File.ReadAllLines(batchfile); for (var
设置图像2=
我想查找“set image1=”并将其编辑为“set image1=c:\1.jpg”
现在我不知道如何编辑它。您可以更新阵列。因为替换
行
-变量不会做任何事情,因为它是不可变的
string[] lines = System.IO.File.ReadAllLines(batchfile);
for (var i = 0; i < lines.Length; i++) {
var line = lines[i];
if (line.Contains("set image1=")) {
lines[i] = "set image1=c:\\1.jpg"; // This will replace the entire line
}
}
// Your lines-array have now been changed with your replacements
string[]lines=System.IO.File.ReadAllLines(batchfile);
对于(变量i=0;i
记住退出你的
\
你知道如何进行谷歌搜索吗,提示关键字是Replace,查找如何使用字符串。Replace方法
是否有必要使用Replace-是否“lines[i]=“set image1=c:\\1.jpg”;“同样有效?”
string[] lines = System.IO.File.ReadAllLines(batchfile);
for (var i = 0; i < lines.Length; i++) {
var line = lines[i];
if (line.Contains("set image1=")) {
lines[i] = "set image1=c:\\1.jpg"; // This will replace the entire line
}
}
// Your lines-array have now been changed with your replacements