小编Kuy*_*aye的帖子

编辑ini文件

我找到了一些与编辑ini文件的某个部分完美配合的代码,但它只选择了我要编辑的第一行实例.我知道我可以手动输入我想要开始编辑的代码中的所有索引,但是知道事情如何随着时间的推移而改变,可能会对ini文件进行更改,然后索引也会发生变化.有人能解释一下这个问题吗?

const string FileName = "File.ini";
string file= File.ReadAllText(FileName);

const string Pattern = @"pattern = (?<Number>)";

Match match = Regex.Match(config, Pattern, RegexOptions.IgnoreCase);

if (match.Success)
{
    int index = match.Groups["Number"].Index;

    string newText= **********;
    file = file.Remove(index, 21);
    file = file.Insert(index, newText);

    File.WriteAllText(FileName, file);
}  
Run Code Online (Sandbox Code Playgroud)

.net c# ini file edit

0
推荐指数
1
解决办法
793
查看次数

标签 统计

.net ×1

c# ×1

edit ×1

file ×1

ini ×1