Remove or Convert ' to (')

前端 未结 3 1417
粉色の甜心
粉色の甜心 2021-01-18 00:16

I am consuming an api and I noticed that it comes back with \"'s\" and not an apostrophe. Since I am not going to be displaying this text in html this w

3条回答
  •  春和景丽
    2021-01-18 00:58

    The MatchEveluator is available since .NET 1.0 and comes in handy if you want to address this problem in a more generic fashion - i.e. do more than just HTML character decoding. The general recipe looks like this:

    MatchEvaluator ev = (Match m) => Char.ToString((char)Int32.Parse(m.Groups[1].Value));
    string result = Regex.Replace("The king's key.";, @"&#(\d+);", ev);
    

提交回复
热议问题