Sdílet prostřednictvím


Encoding.WebName Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Text
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overridable ReadOnly Property WebName As String
public virtual string WebName { get; }

Property Value

Type: System.String
The IANA name for the current Encoding.

Remarks

The WebName property returns an IANA-registered name for the encoding. It returns the strings shown in the following table for the encodings supported by Silverlight.

Encoding

WebName property value

UTF8

utf-8

Unicode

utf-16

BigEndianUnicode

utf-16BE

Examples

The following example displays the WebName property for each of the encodings supported by the .NET Framework for Silverlight.

Imports System.Text

Public Module Example
   Public Sub Demo(outputBlock As System.Windows.Controls.TextBlock)
      Dim encodingName As String

      ' Get UTF8 encoding object.
      Dim enc8 As Encoding = Encoding.Utf8
      encodingName = enc8.WebName
      outputBlock.Text += String.Format("{0}: {1}", enc8.ToString(), _
                                        enc8.WebName) + vbCrLF
      outputBlock.Text += CStr(enc8.Equals(Encoding.GetEncoding(encodingName))) + vbCrLf

      ' Get UTF16 encoding object.
      Dim enc16 As Encoding = Encoding.Unicode
      encodingName = enc16.WebName
      outputBlock.Text += String.Format("{0}: {1}", enc16.ToString(), _
                                        enc16.WebName) + vbCrLF
      outputBlock.Text += CStr(enc16.Equals(Encoding.GetEncoding(encodingName))) + vbCrLf

      ' Get UTF16 big endian encoding object.
      enc16 = Encoding.BigEndianUnicode
      encodingName = enc16.WebName
      outputBlock.Text += String.Format("{0}: {1}", enc16.ToString(), _
                                        enc16.WebName) + vbCrLF
      outputBlock.Text += CStr(enc16.Equals(Encoding.GetEncoding(encodingName))) + vbCrLf
   End Sub
End Module
' The example displays the following output:
'     System.Text.UTF8Encoding: utf-8
'     True
'     System.Text.UnicodeEncoding: utf-16
'     True
'     system.Text.UnicodeEncoding: utf-16BE
'     True
using System;
using System.Text;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      string encodingName;

      // Get UTF8 encoding object.
      Encoding enc8 = Encoding.UTF8;
      encodingName = enc8.WebName;
      outputBlock.Text += String.Format("{0}: {1}\n", enc8.ToString(), enc8.WebName);
      outputBlock.Text += enc8.Equals(Encoding.GetEncoding(encodingName)) + "\n";

      // Get UTF16 encoding object.
      Encoding enc16 = Encoding.Unicode;
      encodingName = enc16.WebName;
      outputBlock.Text += String.Format("{0}: {1}\n", enc16.ToString(), enc16.WebName);
      outputBlock.Text += enc16.Equals(Encoding.GetEncoding(encodingName)) + "\n";

      // Get UTF16 big endian encoding object.
      enc16 = Encoding.BigEndianUnicode;
      encodingName = enc16.WebName;
      outputBlock.Text += String.Format("{0}: {1}\n", enc16.ToString(), enc16.WebName);
      outputBlock.Text += enc16.Equals(Encoding.GetEncoding(encodingName)) + "\n";
   }
}
// The example displays the following output:
//     System.Text.UTF8Encoding: utf-8
//     True
//     System.Text.UnicodeEncoding: utf-16
//     True
//     system.Text.UnicodeEncoding: utf-16BE
//     True

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.