I suspect you want to replace placeholders such as {ID}
and {Name}
with the values from your list of objects. You could use a regex with a patterns such as
\{(?<key>[A-Za-z]+)\}
Which will find all instances of {something}
and allow you to extract the something
in order to get a value from your list.
Using the overload of Regex.Match
which takes an input string and a MatchEvaluator
delegate, would allow you to get the right value:
var myObject = new Dictionary<string,string>(){
{"ID","1"},
{"Name","Bob Jones"},
{"Description","A very nice man"},
{"Value","1000"},
{"Status","New"},
};
var regex = new Regex(@"\{(?<key>[A-Za-z]+)\}");
var input = "The Name of the Item with the Id {ID} is {Name}. It's Description is {Description}. It has the Value {Value} and the Status {Status}.";
string result = regex.Replace(input, m => myObject[m.Groups["key"].Value]);
Console.WriteLine(result);
Live example: http://rextester.com/FLGTQW95860
The dictionary in that example is just to demonstrate the usage of the regex - there is no reason that couldnt be a DataRow
or a custom object, or any other container for the properties.
Of course this solution does not contain any error handling (such as a placeholder where the property does not exist), which I suspect you will want to include if you're allowing the user to specify the string(s).