/// <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?
@"\[p\:(\b\d+\b)\]"instead if your expression forpattern. Means the same thing and is more readable.@"\[p:(\d+)\]". The colon doesn't need escaping and the word boundaries are redundant.