So, I want to format a string using input parameter and not the index placeholders. Preferably I would like to use a Dictionary. but I am not sure how to implement it.
var str = "I have {Bal} coins"; dictionary.Add("Bal", 20); var output = Expected Output: I have 20 coins.
I can use String format like below:
var str = "I have {0} coins"; var output = String.Format(str, 20); My requirement is such that I need to use Dictionary.
FormattableStringand your dictionary. The former is like an interpolated string (same syntax) but if the method accepts that type it doesn't actually format the args, but rather let's you inspect the string and the format parameters and format it yourself.. That is if$"I have {dictionary[“bal"]} coins"doesn't sufficeStringBuilder.Replacelike in this example stackoverflow.com/questions/36759694/…