Delete or Convert 'to (')

I consume the api and I noticed that it returns with "'s" and not an apostrophe. Since I am not going to display this text in html, this will make my text look strange when I show it to the user.

How can I delete or convert (preferred)? I donโ€™t know if this api I am working with will send more of these special codes, so I donโ€™t know if I can just make a replacement.

+4
source share
3 answers

Starting with .NET 4.0, you can use System.Web.HttpUtility.HtmlDecode (located in the System.Web.dll assembly in the System.Web ).

Or you can use the System.Net.WebUtility.HtmlDecode function, you donโ€™t even need an additional link for this (because it is in the System.dll assembly in the System.Net namespace).

Using:

 string myStringToDecode = "Hello 'World'"; string decodedString = System.Web.HttpUtility.HtmlDecode(myStringToDecode); // or string decodedString = System.Net.WebUtility.HtmlDecode(myStringToDecode); 
+8
source

MatchEveluator is available with .NET 1.0 and comes in handy if you want to solve this problem in a more general way - that is, do more than just decode HTML characters . The general recipe is as follows:

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

Why aren't you uysing String.Replace Method (String, String) for this purpose. Just find your line and replace it with the required one.

 string myStringToDecode = "Hello 'World'"; myStringToDecode.Replace("'","'"); 
0
source

Source: https://habr.com/ru/post/1486723/


All Articles