• 欢迎光临~

使用Regex正则表达式替换.txt文本文件中指定的词

开发技术 开发技术 2022-11-19 次浏览

 

 1         /// <summary>
 2         /// 替换文本文件中的词
 3         /// </summary>
 4         /// <param name="filePath"></param>
 5         /// <param name="oldWord"></param>
 6         /// <param name="newWord"></param>
 7         public static void ReplaceWordInTxt(string fliePath, string oldWord, string newWord)
 8         {
 9             string target = File.ReadAllText(fliePath);
10             var strFile = Regex.Replace(target, @"b" + oldWord + @"b", newWord);
11             File.WriteAllText(fliePath, strFile);
12         }

参考:https://stackoverflow.com/questions/13544425/how-can-i-replace-a-word-in-a-txt-file-in-c-sharp

程序员灯塔
转载请注明原文链接:使用Regex正则表达式替换.txt文本文件中指定的词
喜欢 (0)
违法和不良信息举报电话:022-22558618 举报邮箱:dljd@tidljd.com