c# Regex match and replace using function

前端 未结 2 687
抹茶落季
抹茶落季 2021-01-27 00:29
/// 
/// Given HTML overlay for an image in the store, render it.
/// [p:n] renders as price for item ID n
/// 
/// Rendere         


        
2条回答
  •  隐瞒了意图╮
    2021-01-27 00:49

    You can only use the $1 notation if the replacement argument is a string, so you ended up passing $1 as a literal string to the int.Parse method.

    Instead, use the (String, String, MatchEvaluator) overload with an anonymous method:

    Regex.Replace(overlayHTML, pattern, 
    match => FormatCurrency(GetItemPriceOnDate(DateTime.Now, currencyID, int.Parse(match.Groups[1].Value)))
    )
    

提交回复
热议问题