Skip to content

Recursively interpolate strings with a collection of key-value-pairs in .NET with configureable start and end tags.

License

Notifications You must be signed in to change notification settings

TobiStr/RecursiveStringInterpolation

Repository files navigation

RecursiveStringInterpolation

Tests

Recursively interpolate strings with a given collection of key-value-pairs in .NET with configureable start and end tags.

Information

The package uses regex, to match the opening and closing tags and replaces the matched variables with the values in the dictionary.

Add Nuget-Package

dotnet add package RecursiveStringInterpolation

Usage

Import Namespace:

  using String.Interpolation.Recursive;

Initialize:

    //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);

Interpolate a string:

    //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"

P.S.:

Let me know, if you like to have more features.

About

Recursively interpolate strings with a collection of key-value-pairs in .NET with configureable start and end tags.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages