How to properly decode accented characters for display
The text file of the raw source file contains the line:
Café (Should be Café)
The text file is a UTF8 file.
The output allows us to say that this is a different text file, so it is not necessary for the web page.
What C # method can I use to output the correct format Café
,?
source to share
You must use SecurityElement.Escape when working with XML files.
HtmlEncode
will encode many additional objects that are not required. XML only requires you to run>, <, &, "and", which does SecurityElement.Escape
.
When reading a file through an XML parser, this transformation is done for you by the parser, you do not need to "decode" it.
EDIT: Of course, this is only useful when writing XML files.
source to share
I think this works:
string utf8String = "Your string";
Encoding utf8 = Encoding.UTF8;
Encoding unicode = Encoding.Unicode;
byte[] utf8Bytes = utf8.GetBytes(utf8String);
byte[] unicodeBytes = Encoding.Convert(utf8, unicode, utf8Bytes);
char[] uniChars = new char[unicode.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)];
unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, uniChars, 0);
string unicodeString = new string(uniChars);
source to share