/// <summary>
/// Given HTML overlay for an image in the store, render it.
/// [p:n] renders as price for item ID n
/// </summary>
/// <returns>Rendered result</returns>
public static string RenderHTMLOverlay(string overlayHTML, int currencyID)
{
const string pattern = "\\[p\\:(\\b\\d+\\b)\\]";
overlayHTML = Regex.Replace(overlayHTML, pattern, FormatCurrency(GetItemPriceOnDate(DateTime.Now, currencyID, int.Parse("$1"))));
return overlayHTML;
}
This doesn’t work because $1 can’t be passed as a parameter correctly to int.Parse.
Exception Details: System.FormatException: Input string was not in a correct format.
Does anyone know how I can work around this limitation?
You can only use the
$1notation if thereplacementargument is a string, so you ended up passing$1as a literal string to theint.Parsemethod.Instead, use the
(String, String, MatchEvaluator)overload with an anonymous method: