How to replace the text between two characters in c#

前端 未结 7 2120
醉梦人生
醉梦人生 2020-12-06 06:24

I am bit confused writing the regex for finding the Text between the two delimiters { } and replace the text with another text in c#,how to replace?

7条回答
  •  时光取名叫无心
    2020-12-06 06:48

    Use Regex with pattern: \{([^\}]+)\}

    Regex yourRegex = new Regex(@"\{([^\}]+)\}");
    string result = yourRegex.Replace(yourString, "anyReplacement");
    

提交回复
热议问题