UTF7Encoding クラス
アセンブリ: mscorlib (mscorlib.dll 内)


エンコーディングは、Unicode 文字のセットをバイト シーケンスに変換するプロセスです。デコードはその逆になります。エンコードされたバイト シーケンスを Unicode 文字のセットに変換するプロセスです。
Unicode Standard では、サポートされるすべてのスクリプトについて、各文字にコード ポイント (数値) を割り当てています。コード ポイントのエンコードには UTF (Unicode Transformation Format) が使用されます。Unicode Standard バージョン 3.2 では、次の UTF が使用されています。
![]() |
---|
オブジェクトのシリアル化と逆シリアル化を行う際に使用した .NET Framework のバージョンが異なる場合、UTF-7 でエンコードされたオブジェクトの状態は保持されません。 |

次のコード例は、UTF7Encoding を使用して、Unicode 文字列をエンコードし、その結果をバイト配列に格納する方法を示しています。バイト配列を再度文字列にデコードしても、データの損失はありません。
Imports System Imports System.Text Imports Microsoft.VisualBasic.Strings Class UTF7EncodingExample Public Shared Sub Main() ' Create a UTF-7 encoding. Dim utf7 As New UTF7Encoding() ' A Unicode string with two characters outside a 7-bit code range. Dim unicodeString As String = _ "This Unicode string contains two characters " & _ "with codes outside a 7-bit code range, " & _ "Pi (" & ChrW(928) & ") and Sigma (" & ChrW(931) & ")." Console.WriteLine("Original string:") Console.WriteLine(unicodeString) ' Encode the string. Dim encodedBytes As Byte() = utf7.GetBytes(unicodeString) Console.WriteLine() Console.WriteLine("Encoded bytes:") Dim b As Byte For Each b In encodedBytes Console.Write("[{0}]", b) Next b Console.WriteLine() ' Decode bytes back to string. ' Notice Pi and Sigma characters are still present. Dim decodedString As String = utf7.GetString(encodedBytes) Console.WriteLine() Console.WriteLine("Decoded bytes:") Console.WriteLine(decodedString) End Sub End Class
using System; using System.Text; class UTF7EncodingExample { public static void Main() { // Create a UTF-7 encoding. UTF7Encoding utf7 = new UTF7Encoding(); // A Unicode string with two characters outside a 7-bit code range. String unicodeString = "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. Byte[] encodedBytes = utf7.GetBytes(unicodeString); Console.WriteLine(); Console.WriteLine("Encoded bytes:"); foreach (Byte b in encodedBytes) { Console.Write("[{0}]", b); } Console.WriteLine(); // Decode bytes back to string. // Notice Pi and Sigma characters are still present. String decodedString = utf7.GetString(encodedBytes); Console.WriteLine(); Console.WriteLine("Decoded bytes:"); Console.WriteLine(decodedString); } }
using namespace System; using namespace System::Text; using namespace System::Collections; int main() { // Create a UTF-7 encoding. UTF7Encoding^ utf7 = gcnew UTF7Encoding; // A Unicode string with two characters outside a 7-bit code range. String^ unicodeString = L"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. array<Byte>^encodedBytes = utf7->GetBytes( unicodeString ); Console::WriteLine(); Console::WriteLine( "Encoded bytes:" ); IEnumerator^ myEnum = encodedBytes->GetEnumerator(); while ( myEnum->MoveNext() ) { Byte b = safe_cast<Byte>(myEnum->Current); Console::Write( "[{0}]", b ); } Console::WriteLine(); // Decode bytes back to string. // Notice Pi and Sigma characters are still present. String^ decodedString = utf7->GetString( encodedBytes ); Console::WriteLine(); Console::WriteLine( "Decoded bytes:" ); Console::WriteLine( decodedString ); }
import System.*; import System.Text.*; class UTF7EncodingExample { public static void main(String[] args) { // Create a UTF-7 encoding. UTF7Encoding utf7 = new UTF7Encoding(); // A Unicode string with two characters outside a 7-bit code range. String unicodeString = "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. ubyte encodedBytes[] = utf7.GetBytes(unicodeString); Console.WriteLine(); Console.WriteLine("Encoded bytes:"); for(int iCtr = 0; iCtr < encodedBytes.length; iCtr++) { ubyte b = encodedBytes[iCtr]; Console.Write("[{0}]", String.valueOf(b)); } Console.WriteLine(); // Decode bytes back to string. // Notice Pi and Sigma characters are still present. String decodedString = utf7.GetString(encodedBytes); Console.WriteLine(); Console.WriteLine("Decoded bytes:"); Console.WriteLine(decodedString); } //main } //UTF7EncodingExample

System.Text.Encoding
System.Text.UTF7Encoding


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- UTF7Encoding クラスのページへのリンク