UTF7Encoding

UTF7Encoding


Represents a UTF-7 encoding of Unicode characters.


Implements:

Encoding 
ICloneable 
IObject 

Public:

Properties:

NameDescription
 BodyName (get) Gets the encoding name to be used in with the mail agent body tags.  
 CodePage (get) Gets the code page identifier for this encoding.  
 DecoderFallback (get) Gets the current DecoderFallback instance used by the encoding.  
 DecoderFallback (set) Sets the DecoderFallback to be used by this encoding instance.  
 EncoderFallback (get) Gets the current EncoderFallback instance used by the encoding.  
 EncoderFallback (set) Sets the EncoderFallback to be used by this encoding instance.  
 EncodingName (get) Gets the name of this encoding.  
 HeaderName (get) Gets the encoding name to be used in with the mail agent header tags.  
 IsBrowserDisplay (get) Gets if this encoding can be used by browsers to display text.  
 IsBrowserSave (get) Gets if this encoding can be used to save data with this encoding.  
 IsMailNewsDisplay (get) Gets if this encoding can be used to display mail and news by mail and news clients.  
 IsMailNewsSave (get) Gets if this encoding can be used to save date by mail and news clients.  
 IsReadOnly (get) When implemented in a derived class, gets a value indicating whether the current encoding is read-only.  
 IsSingleByte (get) Gets if the current encoding uses single-byte code points.  
 WebName (get) Gets the encoding name registered with the Internet Assigned Numbers Authority.  
 WindowsCodePage (get) Gets the Windows Operating Systems code page for this encoding.  

Methods:

NameDescription
 Clone Creates a clone of the current Encoding instance.  
 Equals Returns a boolean indicating if the value and this object instance are the same instance.  
 GetByteCount Returns the number of bytes that would be produced from the set of characters using this encoding.  
 GetBytes Encodes a set of characters into an array of bytes.  
 GetBytesEx Encodes a set of characters into an array of bytes, returning the number of bytes produced.  
 GetCharCount Returns the number of characters that would be produced by decoding a byte array.  
 GetChars Decodes a set of bytes into a set of characters.  
 GetCharsEx Decodes a set of bytes into the supplied Integer array.  
 GetDecoder Returns a decoder that maintains state.  
 GetEncoder Returns an encoder that maintains state.  
 GetHashCode Returns a pseudo-unique number identifying this instance.  
 GetMaxByteCount Returns the maximum number of bytes that can be created from a specific number of characters.  
 GetMaxCharCount Returns the maximum number of characters than can be decoded from the number of bytes specified.  
 GetPreamble Returns an array of bytes that represents this encoding.  
 GetString Decodes a set of bytes into a String.  
 ToString Returns a string representation of this object instance.  

Remarks

Encoding is the process of transforming a set of Unicode characters into a sequence of bytes. Decoding is the process of transforming a sequence of encoded bytes into a set of Unicode characters.

The UTF-7 encoding represents Unicode characters as sequences of 7-bit ASCII characters. This encoding supports certain protocols for which it is required, most often e-mail or newsgroup protocols. Since UTF-7 is not particularly secure or robust, and most modern systems allow 8-bit encodings, UTF-8 should normally be preferred to UTF-7.

Caution
UTF7Encoding does not provide error detection. For security reasons, you should use UTF8Encoding, UnicodeEncoding, or UTF32Encoding and enable error detection.

Information about the UTF-7 encoding scheme can be found at http://www.faqs.org/rfcs/rfc2152.html.

The GetByteCount method determines how many bytes result in encoding a set of Unicode characters, and the GetBytes method performs the actual encoding.

Likewise, the GetCharCount method determines how many characters result in decoding a sequence of bytes, and the GetChars and GetString methods perform the actual decoding.

UTF7Encoding corresponds to the Windows code page 65000.

Examples

The following code example demonstrates how to use a UTF7Encoding to encode a string of Unicode characters and store them in a byte array. Notice that when the byte array is decoded back to a string, no data is lost.

Public Sub Main()
    Dim UTF7            As New UTF7Encoding
    Dim UnicodeString   As String
    Dim EncodedBytes()  As Byte
    Dim DecodedString   As String
    Dim b               As Variant
    
    Set Console.OutputEncoding = Encoding.UTF8
    
    ' A Unicode string with two characters outside a 7-bit code range.
    UnicodeString = t("This Unicode string contains two characters with codes outside a 7-bit code range, Pi (\u03a0) and Sigma (\u03a3).")
    
    Console.WriteLine "Original string:"
    Console.WriteLine UnicodeString
    
    ' Encode the string.
    EncodedBytes = UTF7.GetBytes(UnicodeString)
    Console.WriteLine
    Console.WriteLine "Encoded bytes:"
    
    For Each b In EncodedBytes
        Console.WriteValue "[{0}]", b
    Next
    
    Console.WriteLine
    
    ' Decode bytes back to string.
    ' Notice Pi and Sigma characters are still present.
    DecodedString = UTF7.GetString(EncodedBytes)
    Console.WriteLine
    Console.WriteLine "Decoded bytes:"
    Console.WriteLine DecodedString
    Console.ReadKey
End Sub

See Also

Project CorLib Overview

Class UTF7Encoding Overview

Constructors

Encoding

ASCIIEncoding

UTF8Encoding

UTF32Encoding

UnicodeEncoding