Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard literal constant that I can use instead of "utf-8" in C# (.Net 3.5)?

I would like to find a better way to do this:

XmlNode nodeXML = xmlDoc.AppendChild(
    xmlDoc.CreateXmlDeclaration( "1.0", "utf-8", String.Empty) );

I do not want to think about "utf-8" vs "UTF-8" vs "UTF8" vs "utf8" as I type code. I would like to make my code less prone to typos. I am sure that some standard library has declatred "utf-8" as a const / readonly string. How can I find it? Also, what about "1.0"? I am assuming that major XML versions have been enumerated somewhere as well.

Thanks!

like image 754
Hamish Grubijan Avatar asked May 11 '10 17:05

Hamish Grubijan


2 Answers

Try Encoding.UTF8.WebName.

like image 184
Ben M Avatar answered Oct 13 '22 00:10

Ben M


You can use Encoding.UTF8 from System.Text.

like image 41
JasCav Avatar answered Oct 12 '22 23:10

JasCav