C# UnicodeEncoding WebName

Description

UnicodeEncoding WebName When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.

Syntax

UnicodeEncoding.WebName has the following syntax.


public virtual string WebName { get; }

Example

The following example includes the WebName in an HTML header.


/*from   w w  w . j  a  v  a 2s  .  c  o m*/
using System;
using System.IO;
using System.Text;
using System.Web;


public class ExampleClass
{
    public static void Main(string[] args)
    {
        Encoding encoding = Encoding.UTF8;
        StreamWriter writer = new StreamWriter("Encoding.html", false, encoding);

        writer.WriteLine("<html><head>");
        writer.WriteLine("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=" +
                               encoding.WebName + "\">");

        writer.WriteLine("</head><body>");
        writer.WriteLine("<p>" + encoding.EncodingName + "</p>");
        writer.WriteLine("</body></html>");
        writer.Flush();
        writer.Close();

        foreach (EncodingInfo ei in Encoding.GetEncodings())
        {
            Encoding e = ei.GetEncoding();

            Console.Write("{0,-18} ", e.WebName);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding