多くの文字列と多くの置換を含むこのファイルがあり、文字列を置換で置き換えてから、テキストファイルを保存したいのですが、これは私が試したものですが、悪い仕事をしました:
StreamReader sr = new StreamReader(fullPath + "\\DICT_J.txt", Encoding.Unicode);
string cdID;
string str;
while (sr.Peek() >= 0)
{
string[] temp = sr.ReadLine().Split('^');
if (temp.Length == 3)
{
cdID = temp[1];
str = temp[2];
File.WriteAllText(path, Regex.Replace(File.ReadAllText(path), str, cdID), Encoding.Unicode);
}
}
sr.Close();
sr.Dispose();
ここ(SOF では改行が許可されていないため、ここに投稿できませんでした) は、置換を含むファイルのサンプルであり、テンプレートは次のとおりです: 行 ID^置換^置換される文字列