且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用该字符串中的标记更新长字符串的某个部分

更新时间:2023-11-06 14:25:58

我可能会使用正则表达式:

I would probably use a regex:
public static Regex replaceField2 = new Regex(
      "(?<=field2:\").*?(?=\")",
    RegexOptions.IgnoreCase
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );

// Replace the matched text in the InputText using the replacement pattern
string result = replaceField2.Replace(InputText,"new value for field2");