I want to get and replace the string between special character. e.g. myString = "hello my first string is {String Name} and my Second string is {String Name}"
I want to replace the string between "{" "}".
I want to get and replace the string between special character. e.g. myString = "hello my first string is {String Name} and my Second string is {String Name}"
I want to replace the string between "{" "}".
You can do that with a Regex like this:
Regex.Replace(input, "{.*?}", replaceString);
For example:
string input = "This is the {text}";
string replace = "content";
string result = Regex.Replace(input, "{.*?}", replace);
See also How do I remove all HTML tags from a string without knowing which tags are in it?
string content = "{dsdhs},{sdsds}";
List<string> tempList = new List<string>();
Regex topicRegex = new Regex(@"\{(.*?)\}", RegexOptions.Compiled);
foreach (Match item in topicRegex.Matches(content))
tempList.Add(item.Value);
You can use Regex
var input = "User Name {stringToReplace}";
var output = Regex.Replace(input, @" ?\{.*?\}", "NewString");
Console.WriteLine(output);
People are giving regex answers but it sounds more like you're describing string interpolation.
var string1 = "string 1";
var string2 = "string 2";
var myString = $"hello my first string is {string1} and my Second string is {string2}";
For a more detailed explanation: https://msdn.microsoft.com/en-GB/library/dn961160.aspx