views:

136

answers:

2

Hi, I have a string which looks like:

 À l'intérieur

But it needs to be:

 À l'intérieur

I tried changing the conversion. I know it's read as ASCII encoding. So I tried using the code:

      ASCIIEncoding ASCII  = new System.Text.ASCIIEncoding();
      Byte[] BytesMessage = ASCII.GetBytes(Title);
      Title = Encoding.UTF8.GetString(BytesMessage);

I tried switching between the different encodings but it didn't help much. Is there a way to fix this?

Thx!

+6  A: 

Well, this is actually not a character encoding (such as ASCII or UTF-8) but rather a higher-level protocol defining escape sequences for arbitrary characters—in this case SGML which serves as the basis for HTML and XML.

You can use the HtmlDecode method of the HttpUtility class to decode it:

PS> Add-Type -AssemblyName system.web
PS> [web.httputility]::HtmlDecode("À l'intérieur")
À l'intérieur

However, this class resides in the System.Web namespace so it's probably not immediately available in a non-ASP.NET project.

Joey
Whoo-hoo! +1 for the Powershell example.
Jeremy McGee
It's the easiest way to test something in .NET without actually firing up Visual Studio, opening one of the dozens ConsoleProject1 solutions, etc. :-)
Joey
+2  A: 

To transcode HTML encoded strings like this use System.Web.HttpUtility.HtmlDecode(Title). You'll need to reference System.Web if this is not a Web application.

Jeremy McGee
Thanks a lot! This is what I needed. For others, to be exact. It's HttpUtility.HtmlDecode(Title).
WtFudgE
Whoops! Thanks for that.
Jeremy McGee