How to replace the text between two characters in c#

前端 未结 7 2174
醉梦人生
醉梦人生 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 07:00

    string s = "data{value here} data";
    int start = s.IndexOf("{");
    int end = s.IndexOf("}", start);
    string result = s.Substring(start+1, end - start - 1);
    s = s.Replace(result, "your replacement value");
    

提交回复
热议问题