How to properly decode accented characters for display
Solution 1
Have you tried System.Web.HttpUtility.HtmlDecode("Café")
? it returns 538M results
Solution 2
This is HTML encoded text. You need to decode it:
string decoded = HttpUtility.HtmlDecode(text);
UPDATE: french symbol "é" has HTML code "é
" so, you need to fix your input string.
Solution 3
You should use SecurityElement.Escape when working with XML files.
HtmlEncode
will encode a lot of extra entities that are not required. XML only requires that you escape >, <, &, ", and ', which SecurityElement.Escape
does.
When reading the file back through an XML parser, this conversion is done for you by the parser, you shouldn't need to "decode" it.
EDIT: Of course this is only helpful when writing XML files.
Fixer
Updated on June 04, 2022Comments
-
Fixer almost 2 years
My raw input file text file contains a string:
Café (Should be Café)
The text file is a UTF8 file.
The output lets say is to another text file, so its not necessarily for a web page.
What C# method(s) can i use to output the correct format,
Café
?