Recursively interpolate strings with a given collection of key-value-pairs in .NET with configureable start and end tags.
The package uses regex, to match the opening and closing tags and replaces the matched variables with the values in the dictionary.
dotnet add package RecursiveStringInterpolation
using String.Interpolation.Recursive;
//Here nearly everything, even longer strings and special characters are supported.
//See tests for examples.
var openingTag = "{";
var closingTag = "}";
var stringInterpolator = new RecursiveStringInterpolator(openingTag, closingTag);
//Provide a string, you want to interpolate
const string testString = "{a}{b}{c}";
//Provide a dictionary, with the key-value-pairs, you want to use for interpolation
var keyValues = new Dictionary<string, string>();
keyValues.Add("a", "a");
keyValues.Add("b", "{a}");
keyValues.Add("c", "{b}");
//Use Interpolator to interpolate the string
var result = stringInterpolator.Interpolate(testString, keyValues);
//result = "aaa"
Let me know, if you like to have more features.