From: https://stackoverflow.com/a/959982/101055
I am trying to use:
using System.Text.RegularExpressions;
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("goodName1", "asdf");
parameters.Add("goodName2", "qwerty");
string text = "this is my {goodName1} template {goodName2} string";
text = Regex.Replace(text, "\{(.+?)\}", m => parameters[m.Groups[1].Value]);
I get 2 build errors on \{(.+?)\}, on { and } exactly.
ERROR > Unrecognized escape sequence
What is wrong here?
try:
A few more details.
The @ sign defines a Verbatim String Literal. This basically says tells the compiler that the string in quotes is not escaped. http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
Optionally, you could have simply doubled up on the back slashes. e.g.:
But, IMHO, the @ sign is much more readable.