Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string FormatDictionary(this string str, Dictionary<string, object> args)
- {
- var rex = new Regex("{.*?}");
- var groups = new List<string>();
- foreach (Match x in rex.Matches(str))
- {
- var strippedVal = x.Value.Trim('{', '}');
- if (!groups.Contains(strippedVal))
- groups.Add(strippedVal);
- }
- var values = new List<object>();
- for (int i = 0; i < groups.Count; i++)
- {
- str = str.Replace("{" + groups[i] + "}", "{" + i + "}");
- values.Add(args.ContainsKey(groups[i]) ? args[groups[i]] : string.Empty);
- }
- return string.Format(str, values.ToArray());
- //return string.Format(str, args);
- }
Advertisement
Add Comment
Please, Sign In to add comment