I think this should be a pretty simple solution but I am having trouble. I am trying to remove all strings within {} including the brackets from another string, and replace them with the string "^~". For example:
input: "{asdf} Hello Stack {over} flow you all are {very} helpful."
output: "^~ Hello Stack ^~ flow you all are ^~ helpful.
Currently I am using regular expressions but this only works to replace strings with only one delimited string. Heres my code and the output:
System.Diagnostics.Debug.WriteLine("s: " + s);
string regex = "(\\{.*\\})";
string output = Regex.Replace(s, regex, "^~");
System.Diagnostics.Debug.WriteLine("output after replace:" + output);
s: {Name}, {Time}, {Date}
output after replace: ^~
s: and {} inches long.
output after replace: and ^~ inches long.
s: {Person}'s {} lbs. {} oz.
output after replace: ^~ oz.
As you can see it works with strings with only one {} but I get an error when there is more than one. There must be something simple I'm doing wrong but I'm not too knowledgable of regular expressions and can't seem to find the answer anywhere.
Perhaps there is an easier way to do this without regular expressions also?