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


エンコーディングは、Unicode 文字のセットをバイト シーケンスに変換するプロセスです。デコードはその逆になります。エンコードされたバイト シーケンスを Unicode 文字のセットに変換するプロセスです。
Unicode Standard では、サポートされるすべてのスクリプトについて、各文字にコード ポイント (数値) を割り当てています。コード ポイントのエンコードには UTF (Unicode Transformation Format) が使用されます。Unicode Standard バージョン 3.2 では、次の UTF が使用されています。
GetByteCount メソッドは、Unicode 文字のセットをエンコードした結果得られるバイト数を確認します。実際のエンコードは、GetBytes メソッドによって実行されます。
同様に、GetCharCount メソッドは、バイト シーケンスをデコードした結果得られる文字数を確認します。実際のデコードは、GetChars メソッドと GetString メソッドによって実行されます。
エンコーダでは、最上位バイトが先頭に配置されるビッグ エンディアン バイト順、または最下位バイトが先頭に配置されるリトル エンディアン バイト順が使用されます。たとえば、Latin の大文字 A (コード ポイント U+0041) は次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 00 41
-
リトル エンディアン バイト順 : 41 00 00 00
UTF32Encoding は、オプションでプリアンブルを提供します。プリアンブルは、エンコーディング プロセスで得られたバイト シーケンスの先頭に付加できるバイトの配列です。プリアンブルにバイト順マーク (コード ポイント U+FEFF) が含まれる場合、デコーダはバイト順および変換形式 (UTF) を判断できます。Unicode バイト順マークは、次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 FE FF
-
リトル エンディアン バイト順 : FF FE 00 00
通常、ネイティブなバイト順で Unicode 文字を格納した方が効率的です。たとえば、Intel のコンピュータなど、リトル エンディアンのプラットフォームでは、リトル エンディアンのバイト順を使用した方が効率的です。
GetPreamble メソッドは、バイト順マークを格納するバイト配列を返します。このバイト配列がエンコード済みストリームの前に付加されていると、使用されているエンコーディング形式をデコーダが識別するのに役立ちます。
Unicode エンコーディング、バイト順、およびバイト順マークの詳細については、www.unicode.org の「Unicode Standard」を参照してください。
![]() |
---|
エラー検出を有効にしてクラス インスタンスの安全性を向上させるには、throwOnInvalidCharacters パラメータを受け取る UTF32Encoding コンストラクタを使用し、このパラメータを true に設定します。エラー検出を有効にすると、メソッドは、無効な文字シーケンスやバイト シーケンスを検出したときに、ArgumentException をスローします。エラー検出を無効にすると、例外はスローされず、無効なシーケンスは全般に無視されます。 |
UTF32Encoding は、Windows コード ページ 12000 (リトル エンディアン バイト順) と 12001 (ビッグ エンディアン バイト順) に対応しています。

次のコード例は、エラー検出を有効にした場合と無効にした場合の UTF32Encoding の動作を示しています。
Imports System Imports System.Text Imports Microsoft.VisualBasic Public Class SamplesUTF32Encoding Public Shared Sub Main() ' Create an instance of UTF32Encoding using little-endian byte order. ' This will be used for encoding. Dim u32LE As New UTF32Encoding(False, True) ' Create two instances of UTF32Encoding using big-endian byte order: one with error detection and one without. ' These will be used for decoding. Dim u32withED As New UTF32Encoding(True, True, True) Dim u32noED As New UTF32Encoding(True, True, False) ' Create byte arrays from the same string containing the following characters: ' Latin Small Letter Z (U+007A) ' Latin Small Letter A (U+0061) ' Combining Breve (U+0306) ' Latin Small Letter AE With Acute (U+01FD) ' Greek Small Letter Beta (U+03B2) ' a high-surrogate value (U+D8FF) ' a low-surrogate value (U+DCFF) Dim myStr As String = "za" & ChrW(&H0306) & ChrW(&H01FD) & ChrW(&H03B2) & ChrW(&HD8FF) & ChrW(&HDCFF) ' Encode the string using little-endian byte order. Dim myBytes(u32LE.GetByteCount(myStr)) As Byte u32LE.GetBytes(myStr, 0, myStr.Length, myBytes, 0) ' Decode the byte array with error detection. Console.WriteLine("Decoding with error detection:") PrintDecodedString(myBytes, u32withED) ' Decode the byte array without error detection. Console.WriteLine("Decoding without error detection:") PrintDecodedString(myBytes, u32noED) End Sub 'Main ' Decode the bytes and display the string. Public Shared Sub PrintDecodedString(bytes() As Byte, enc As Encoding) Try Console.WriteLine(" Decoded string: {0}", enc.GetString(bytes, 0, bytes.Length)) Catch e As System.ArgumentException Console.WriteLine(e.ToString()) End Try Console.WriteLine() End Sub 'PrintDecodedString End Class 'SamplesUTF32Encoding
using System; using System.Text; public class SamplesUTF32Encoding { public static void Main() { // Create an instance of UTF32Encoding using little-endian byte order. // This will be used for encoding. UTF32Encoding u32LE = new UTF32Encoding( false, true ); // Create two instances of UTF32Encoding using big-endian byte order: one with error detection and one without. // These will be used for decoding. UTF32Encoding u32withED = new UTF32Encoding( true, true, true ); UTF32Encoding u32noED = new UTF32Encoding( true, true, false ); // Create byte arrays from the same string containing the following characters: // Latin Small Letter Z (U+007A) // Latin Small Letter A (U+0061) // Combining Breve (U+0306) // Latin Small Letter AE With Acute (U+01FD) // Greek Small Letter Beta (U+03B2) // a high-surrogate value (U+D8FF) // a low-surrogate value (U+DCFF) String myStr = "za\u0306\u01FD\u03B2\uD8FF\uDCFF"; // Encode the string using little-endian byte order. byte[] myBytes = new byte[u32LE.GetByteCount( myStr )]; u32LE.GetBytes( myStr, 0, myStr.Length, myBytes, 0 ); // Decode the byte array with error detection. Console.WriteLine( "Decoding with error detection:" ); PrintDecodedString( myBytes, u32withED ); // Decode the byte array without error detection. Console.WriteLine( "Decoding without error detection:" ); PrintDecodedString( myBytes, u32noED ); } // Decode the bytes and display the string. public static void PrintDecodedString( byte[] bytes, Encoding enc ) { try { Console.WriteLine( " Decoded string: {0}", enc.GetString( bytes, 0, bytes.Length ) ); } catch ( System.ArgumentException e ) { Console.WriteLine( e.ToString() ); } Console.WriteLine(); } }
using namespace System; using namespace System::Text; void PrintDecodedString( array<Byte>^bytes, Encoding^ enc ); int main() { // Create an instance of UTF32Encoding using little-endian byte order. // This will be used for encoding. UTF32Encoding^ u32LE = gcnew UTF32Encoding( false,true ); // Create two instances of UTF32Encoding using big-endian byte order: one with error detection and one without. // These will be used for decoding. UTF32Encoding^ u32withED = gcnew UTF32Encoding( true,true,true ); UTF32Encoding^ u32noED = gcnew UTF32Encoding( true,true,false ); // Create byte arrays from the same string containing the following characters: // Latin Small Letter Z (U+007A) // Latin Small Letter A (U+0061) // Combining Breve (U+0306) // Latin Small Letter AE With Acute (U+01FD) // Greek Small Letter Beta (U+03B2) String^ myStr = L"za\u0306\u01FD\u03B2\xD8FF\xDCFF"; // Encode the string using little-endian byte order. array<Byte>^myBytes = gcnew array<Byte>(u32LE->GetByteCount( myStr )); u32LE->GetBytes( myStr, 0, myStr->Length, myBytes, 0 ); // Decode the byte array with error detection. Console::WriteLine( "Decoding with error detection:" ); PrintDecodedString( myBytes, u32withED ); // Decode the byte array without error detection. Console::WriteLine( "Decoding without error detection:" ); PrintDecodedString( myBytes, u32noED ); } // Decode the bytes and display the string. void PrintDecodedString( array<Byte>^bytes, Encoding^ enc ) { try { Console::WriteLine( " Decoded string: {0}", enc->GetString( bytes, 0, bytes->Length ) ); } catch ( System::ArgumentException^ e ) { Console::WriteLine( e ); } Console::WriteLine(); }
import System.*; import System.Text.*; public class SamplesUTF32Encoding { public static void main(String[] args) { // Create an instance of UTF32Encoding using little-endian byte order. // This will be used for encoding. UTF32Encoding u32LE = new UTF32Encoding(false, true); // Create two instances of UTF32Encoding using big-endian byte order: // one with error detection and one without. // These will be used for decoding. UTF32Encoding u32withED = new UTF32Encoding(true, true, true); UTF32Encoding u32noED = new UTF32Encoding(true, true, false); // Create byte arrays from the same string containing the // following characters: // Latin Small Letter Z (U+007A) // Latin Small Letter A (U+0061) // Combining Breve (U+0306) // Latin Small Letter AE With Acute (U+01FD) // Greek Small Letter Beta (U+03B2) // a high-surrogate value (U+D8FF) // a low-surrogate value (U+DCFF) String myStr = "za\u0306\u01FD\u03B2\uD8FF\uDCFF"; // Encode the string using little-endian byte order. ubyte myBytes[] = new ubyte[u32LE.GetByteCount(myStr)]; u32LE.GetBytes(myStr, 0, myStr.get_Length(), myBytes, 0); // Decode the byte array with error detection. Console.WriteLine("Decoding with error detection:"); PrintDecodedString(myBytes, u32withED); // Decode the byte array without error detection. Console.WriteLine("Decoding without error detection:"); PrintDecodedString(myBytes, u32noED); } //main // Decode the bytes and display the string. public static void PrintDecodedString(ubyte bytes[], Encoding enc) { try { Console.WriteLine(" Decoded string: {0}" , enc.GetString(bytes, 0, bytes.length)); } catch(System.ArgumentException e) { Console.WriteLine(e.ToString()); } Console.WriteLine(); } //PrintDecodedString } //SamplesUTF32Encoding

System.Text.Encoding
System.Text.UTF32Encoding


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


UTF32Encoding コンストラクタ ()
アセンブリ: mscorlib (mscorlib.dll 内)


このコンストラクタは、リトル エンディアン バイト順を使用し、Unicode バイト順マークを付加し、無効なエンコーディングを検出したときに例外をスローしないインスタンスを作成します。
![]() |
---|
セキュリティ上の理由から、throwOnInvalidCharacters パラメータを受け取るコンストラクタを使用して、このパラメータを true に設定することにより、エラー検出を有効にすることをお勧めします。 |
エンコーダでは、最上位バイトが先頭に配置されるビッグ エンディアン バイト順、または最下位バイトが先頭に配置されるリトル エンディアン バイト順が使用されます。たとえば、Latin の大文字 A (コード ポイント U+0041) は次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 00 41
-
リトル エンディアン バイト順 : 41 00 00 00
UTF32Encoding は、オプションでプリアンブルを提供します。プリアンブルは、エンコーディング プロセスで得られたバイト シーケンスの先頭に付加できるバイトの配列です。プリアンブルにバイト順マーク (コード ポイント U+FEFF) が含まれる場合、デコーダはバイト順および変換形式 (UTF) を判断できます。Unicode バイト順マークは、次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 FE FF
-
リトル エンディアン バイト順 : FF FE 00 00
通常、ネイティブなバイト順で Unicode 文字を格納した方が効率的です。たとえば、Intel のコンピュータなど、リトル エンディアンのプラットフォームでは、リトル エンディアンのバイト順を使用した方が効率的です。
バイト順とバイト順マークの詳細については、www.unicode.org の「Unicode Standard」を参照してください。

次のコード例は、さまざまな UTF32Encoding インスタンスのバイト順マークを取得して表示します。
Imports System Imports System.Text Public Class SamplesUTF32Encoding Public Shared Sub Main() ' Create instances of UTF32Encoding, with the byte order mark and without. Dim u32LeNone As New UTF32Encoding() Dim u32BeNone As New UTF32Encoding(True, False) Dim u32LeBom As New UTF32Encoding(False, True) Dim u32BeBom As New UTF32Encoding(True, True) ' Display the preamble for each instance. PrintHexBytes(u32LeNone.GetPreamble()) PrintHexBytes(u32BeNone.GetPreamble()) PrintHexBytes(u32LeBom.GetPreamble()) PrintHexBytes(u32BeBom.GetPreamble()) End Sub 'Main Public Shared Sub PrintHexBytes(bytes() As Byte) If bytes Is Nothing OrElse bytes.Length = 0 Then Console.WriteLine("<none>") Else Dim i As Integer For i = 0 To bytes.Length - 1 Console.Write("{0:X2} ", bytes(i)) Next i Console.WriteLine() End If End Sub 'PrintHexBytes End Class 'SamplesUTF32Encoding 'This code produces the following output. ' '<none> '<none> 'FF FE 00 00 '00 00 FE FF
using System; using System.Text; public class SamplesUTF32Encoding { public static void Main() { // Create instances of UTF32Encoding, with the byte order mark and without. UTF32Encoding u32LeNone = new UTF32Encoding(); UTF32Encoding u32BeNone = new UTF32Encoding( true, false ); UTF32Encoding u32LeBom = new UTF32Encoding( false, true ); UTF32Encoding u32BeBom = new UTF32Encoding( true, true ); // Display the preamble for each instance. PrintHexBytes( u32LeNone.GetPreamble() ); PrintHexBytes( u32BeNone.GetPreamble() ); PrintHexBytes( u32LeBom.GetPreamble() ); PrintHexBytes( u32BeBom.GetPreamble() ); } public static void PrintHexBytes( byte[] bytes ) { if (( bytes == null ) || ( bytes.Length == 0 )) Console.WriteLine( "<none>" ); else { for ( int i = 0; i < bytes.Length; i++ ) Console.Write( "{0:X2} ", bytes[i] ); Console.WriteLine(); } } } /* This code produces the following output. <none> <none> FF FE 00 00 00 00 FE FF */
using namespace System; using namespace System::Text; void PrintHexBytes( array<Byte>^bytes ); int main() { // Create instances of UTF32Encoding, with the byte order mark and without. UTF32Encoding ^ u32LeNone = gcnew UTF32Encoding; UTF32Encoding ^ u32BeNone = gcnew UTF32Encoding( true,false ); UTF32Encoding ^ u32LeBom = gcnew UTF32Encoding( false,true ); UTF32Encoding ^ u32BeBom = gcnew UTF32Encoding( true,true ); // Display the preamble for each instance. PrintHexBytes( u32LeNone->GetPreamble() ); PrintHexBytes( u32BeNone->GetPreamble() ); PrintHexBytes( u32LeBom->GetPreamble() ); PrintHexBytes( u32BeBom->GetPreamble() ); } void PrintHexBytes( array<Byte>^bytes ) { if ( (bytes == nullptr) || (bytes->Length == 0) ) Console::WriteLine( "<none>" ); else { for ( int i = 0; i < bytes->Length; i++ ) Console::Write( "{0:X2} ", bytes[ i ] ); Console::WriteLine(); } } /* This code produces the following output. <none> <none> FF FE 00 00 00 00 FE FF */
import System.*; import System.Text.*; public class SamplesUTF32Encoding { public static void main(String[] args) { // Create instances of UTF32Encoding, with the byte // order mark and without. UTF32Encoding u32LeNone = new UTF32Encoding(); UTF32Encoding u32BeNone = new UTF32Encoding(true, false); UTF32Encoding u32LeBom = new UTF32Encoding(false, true); UTF32Encoding u32BeBom = new UTF32Encoding(true, true); // Display the preamble for each instance. PrintHexBytes(u32LeNone.GetPreamble()); PrintHexBytes(u32BeNone.GetPreamble()); PrintHexBytes(u32LeBom.GetPreamble()); PrintHexBytes(u32BeBom.GetPreamble()); } //main public static void PrintHexBytes(ubyte bytes[]) { if(bytes == null || bytes.length == 0) { Console.WriteLine("<none>"); } else { for(int i = 0; i < bytes.length; i++) { Console.Write("{0:X2} ", ((System.Byte)bytes[i]).ToString("X2")); } Console.WriteLine(); } } //PrintHexBytes } //SamplesUTF32Encoding /* This code produces the following output. FF FE 00 00 <none> FF FE 00 00 00 00 FE FF */

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


UTF32Encoding コンストラクタ (Boolean, Boolean, Boolean)
アセンブリ: mscorlib (mscorlib.dll 内)

Public Sub New ( _ bigEndian As Boolean, _ byteOrderMark As Boolean, _ throwOnInvalidCharacters As Boolean _ )
Dim bigEndian As Boolean Dim byteOrderMark As Boolean Dim throwOnInvalidCharacters As Boolean Dim instance As New UTF32Encoding(bigEndian, byteOrderMark, throwOnInvalidCharacters)
public function UTF32Encoding ( bigEndian : boolean, byteOrderMark : boolean, throwOnInvalidCharacters : boolean )

throwOnInvalidCharacters が true の場合、無効なバイト シーケンスを検出したメソッドは System.ArgumentException をスローします。それ以外の場合は、例外をスローせず、無効なシーケンスを無視します。
![]() |
---|
セキュリティ上の理由から、このコンストラクタを使用して UTF32Encoding クラスのインスタンスを作成し、throwOnInvalidCharacters を true に設定することでエラー検出をオンにすることをお勧めします。 |
エンコーダでは、最上位バイトが先頭に配置されるビッグ エンディアン バイト順、または最下位バイトが先頭に配置されるリトル エンディアン バイト順が使用されます。たとえば、Latin の大文字 A (コード ポイント U+0041) は次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 00 41
-
リトル エンディアン バイト順 : 41 00 00 00
UTF32Encoding は、オプションでプリアンブルを提供します。プリアンブルは、エンコーディング プロセスで得られたバイト シーケンスの先頭に付加できるバイトの配列です。プリアンブルにバイト順マーク (コード ポイント U+FEFF) が含まれる場合、デコーダはバイト順および変換形式 (UTF) を判断できます。Unicode バイト順マークは、次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 FE FF
-
リトル エンディアン バイト順 : FF FE 00 00
通常、ネイティブなバイト順で Unicode 文字を格納した方が効率的です。たとえば、Intel のコンピュータなど、リトル エンディアンのプラットフォームでは、リトル エンディアンのバイト順を使用した方が効率的です。
バイト順とバイト順マークの詳細については、www.unicode.org の「Unicode Standard」を参照してください。

次のコード例は、エラー検出を有効にした場合と無効にした場合の UTF32Encoding の動作を示しています。
Imports System Imports System.Text Imports Microsoft.VisualBasic Public Class SamplesUTF32Encoding Public Shared Sub Main() ' Create an instance of UTF32Encoding using little-endian byte order. ' This will be used for encoding. Dim u32LE As New UTF32Encoding(False, True) ' Create two instances of UTF32Encoding using big-endian byte order: one with error detection and one without. ' These will be used for decoding. Dim u32withED As New UTF32Encoding(True, True, True) Dim u32noED As New UTF32Encoding(True, True, False) ' Create byte arrays from the same string containing the following characters: ' Latin Small Letter Z (U+007A) ' Latin Small Letter A (U+0061) ' Combining Breve (U+0306) ' Latin Small Letter AE With Acute (U+01FD) ' Greek Small Letter Beta (U+03B2) ' a high-surrogate value (U+D8FF) ' a low-surrogate value (U+DCFF) Dim myStr As String = "za" & ChrW(&H0306) & ChrW(&H01FD) & ChrW(&H03B2) & ChrW(&HD8FF) & ChrW(&HDCFF) ' Encode the string using little-endian byte order. Dim myBytes(u32LE.GetByteCount(myStr)) As Byte u32LE.GetBytes(myStr, 0, myStr.Length, myBytes, 0) ' Decode the byte array with error detection. Console.WriteLine("Decoding with error detection:") PrintDecodedString(myBytes, u32withED) ' Decode the byte array without error detection. Console.WriteLine("Decoding without error detection:") PrintDecodedString(myBytes, u32noED) End Sub 'Main ' Decode the bytes and display the string. Public Shared Sub PrintDecodedString(bytes() As Byte, enc As Encoding) Try Console.WriteLine(" Decoded string: {0}", enc.GetString(bytes, 0, bytes.Length)) Catch e As System.ArgumentException Console.WriteLine(e.ToString()) End Try Console.WriteLine() End Sub 'PrintDecodedString End Class 'SamplesUTF32Encoding
using System; using System.Text; public class SamplesUTF32Encoding { public static void Main() { // Create an instance of UTF32Encoding using little-endian byte order. // This will be used for encoding. UTF32Encoding u32LE = new UTF32Encoding( false, true ); // Create two instances of UTF32Encoding using big-endian byte order: one with error detection and one without. // These will be used for decoding. UTF32Encoding u32withED = new UTF32Encoding( true, true, true ); UTF32Encoding u32noED = new UTF32Encoding( true, true, false ); // Create byte arrays from the same string containing the following characters: // Latin Small Letter Z (U+007A) // Latin Small Letter A (U+0061) // Combining Breve (U+0306) // Latin Small Letter AE With Acute (U+01FD) // Greek Small Letter Beta (U+03B2) // a high-surrogate value (U+D8FF) // a low-surrogate value (U+DCFF) String myStr = "za\u0306\u01FD\u03B2\uD8FF\uDCFF"; // Encode the string using little-endian byte order. byte[] myBytes = new byte[u32LE.GetByteCount( myStr )]; u32LE.GetBytes( myStr, 0, myStr.Length, myBytes, 0 ); // Decode the byte array with error detection. Console.WriteLine( "Decoding with error detection:" ); PrintDecodedString( myBytes, u32withED ); // Decode the byte array without error detection. Console.WriteLine( "Decoding without error detection:" ); PrintDecodedString( myBytes, u32noED ); } // Decode the bytes and display the string. public static void PrintDecodedString( byte[] bytes, Encoding enc ) { try { Console.WriteLine( " Decoded string: {0}", enc.GetString( bytes, 0, bytes.Length ) ); } catch ( System.ArgumentException e ) { Console.WriteLine( e.ToString() ); } Console.WriteLine(); } }
using namespace System; using namespace System::Text; void PrintDecodedString( array<Byte>^bytes, Encoding^ enc ); int main() { // Create an instance of UTF32Encoding using little-endian byte order. // This will be used for encoding. UTF32Encoding^ u32LE = gcnew UTF32Encoding( false,true ); // Create two instances of UTF32Encoding using big-endian byte order: one with error detection and one without. // These will be used for decoding. UTF32Encoding^ u32withED = gcnew UTF32Encoding( true,true,true ); UTF32Encoding^ u32noED = gcnew UTF32Encoding( true,true,false ); // Create byte arrays from the same string containing the following characters: // Latin Small Letter Z (U+007A) // Latin Small Letter A (U+0061) // Combining Breve (U+0306) // Latin Small Letter AE With Acute (U+01FD) // Greek Small Letter Beta (U+03B2) String^ myStr = L"za\u0306\u01FD\u03B2\xD8FF\xDCFF"; // Encode the string using little-endian byte order. array<Byte>^myBytes = gcnew array<Byte>(u32LE->GetByteCount( myStr )); u32LE->GetBytes( myStr, 0, myStr->Length, myBytes, 0 ); // Decode the byte array with error detection. Console::WriteLine( "Decoding with error detection:" ); PrintDecodedString( myBytes, u32withED ); // Decode the byte array without error detection. Console::WriteLine( "Decoding without error detection:" ); PrintDecodedString( myBytes, u32noED ); } // Decode the bytes and display the string. void PrintDecodedString( array<Byte>^bytes, Encoding^ enc ) { try { Console::WriteLine( " Decoded string: {0}", enc->GetString( bytes, 0, bytes->Length ) ); } catch ( System::ArgumentException^ e ) { Console::WriteLine( e ); } Console::WriteLine(); }
import System.*; import System.Text.*; public class SamplesUTF32Encoding { public static void main(String[] args) { // Create an instance of UTF32Encoding using little-endian byte order. // This will be used for encoding. UTF32Encoding u32LE = new UTF32Encoding(false, true); // Create two instances of UTF32Encoding using big-endian byte order: // one with error detection and one without. // These will be used for decoding. UTF32Encoding u32withED = new UTF32Encoding(true, true, true); UTF32Encoding u32noED = new UTF32Encoding(true, true, false); // Create byte arrays from the same string containing the // following characters: // Latin Small Letter Z (U+007A) // Latin Small Letter A (U+0061) // Combining Breve (U+0306) // Latin Small Letter AE With Acute (U+01FD) // Greek Small Letter Beta (U+03B2) // a high-surrogate value (U+D8FF) // a low-surrogate value (U+DCFF) String myStr = "za\u0306\u01FD\u03B2\uD8FF\uDCFF"; // Encode the string using little-endian byte order. ubyte myBytes[] = new ubyte[u32LE.GetByteCount(myStr)]; u32LE.GetBytes(myStr, 0, myStr.get_Length(), myBytes, 0); // Decode the byte array with error detection. Console.WriteLine("Decoding with error detection:"); PrintDecodedString(myBytes, u32withED); // Decode the byte array without error detection. Console.WriteLine("Decoding without error detection:"); PrintDecodedString(myBytes, u32noED); } //main // Decode the bytes and display the string. public static void PrintDecodedString(ubyte bytes[], Encoding enc) { try { Console.WriteLine(" Decoded string: {0}" , enc.GetString(bytes, 0, bytes.length)); } catch(System.ArgumentException e) { Console.WriteLine(e.ToString()); } Console.WriteLine(); } //PrintDecodedString } //SamplesUTF32Encoding

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


UTF32Encoding コンストラクタ (Boolean, Boolean)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim bigEndian As Boolean Dim byteOrderMark As Boolean Dim instance As New UTF32Encoding(bigEndian, byteOrderMark)

このコンストラクタは、無効なエンコーディングを検出したときに例外をスローしないインスタンスを作成します。
![]() |
---|
セキュリティ上の理由から、throwOnInvalidCharacters パラメータを受け取るコンストラクタを使用して、このパラメータを true に設定することにより、エラー検出を有効にすることをお勧めします。 |
エンコーダでは、最上位バイトが先頭に配置されるビッグ エンディアン バイト順、または最下位バイトが先頭に配置されるリトル エンディアン バイト順が使用されます。たとえば、Latin の大文字 A (コード ポイント U+0041) は次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 00 41
-
リトル エンディアン バイト順 : 41 00 00 00
UTF32Encoding は、オプションでプリアンブルを提供します。プリアンブルは、エンコーディング プロセスで得られたバイト シーケンスの先頭に付加できるバイトの配列です。プリアンブルにバイト順マーク (コード ポイント U+FEFF) が含まれる場合、デコーダはバイト順および変換形式 (UTF) を判断できます。Unicode バイト順マークは、次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 FE FF
-
リトル エンディアン バイト順 : FF FE 00 00
通常、ネイティブなバイト順で Unicode 文字を格納した方が効率的です。たとえば、Intel のコンピュータなど、リトル エンディアンのプラットフォームでは、リトル エンディアンのバイト順を使用した方が効率的です。
バイト順とバイト順マークの詳細については、www.unicode.org の「Unicode Standard」を参照してください。

次のコード例は、さまざまな UTF32Encoding インスタンスのバイト順マークを取得して表示します。
Imports System Imports System.Text Public Class SamplesUTF32Encoding Public Shared Sub Main() ' Create instances of UTF32Encoding, with the byte order mark and without. Dim u32LeNone As New UTF32Encoding() Dim u32BeNone As New UTF32Encoding(True, False) Dim u32LeBom As New UTF32Encoding(False, True) Dim u32BeBom As New UTF32Encoding(True, True) ' Display the preamble for each instance. PrintHexBytes(u32LeNone.GetPreamble()) PrintHexBytes(u32BeNone.GetPreamble()) PrintHexBytes(u32LeBom.GetPreamble()) PrintHexBytes(u32BeBom.GetPreamble()) End Sub 'Main Public Shared Sub PrintHexBytes(bytes() As Byte) If bytes Is Nothing OrElse bytes.Length = 0 Then Console.WriteLine("<none>") Else Dim i As Integer For i = 0 To bytes.Length - 1 Console.Write("{0:X2} ", bytes(i)) Next i Console.WriteLine() End If End Sub 'PrintHexBytes End Class 'SamplesUTF32Encoding 'This code produces the following output. ' '<none> '<none> 'FF FE 00 00 '00 00 FE FF
using System; using System.Text; public class SamplesUTF32Encoding { public static void Main() { // Create instances of UTF32Encoding, with the byte order mark and without. UTF32Encoding u32LeNone = new UTF32Encoding(); UTF32Encoding u32BeNone = new UTF32Encoding( true, false ); UTF32Encoding u32LeBom = new UTF32Encoding( false, true ); UTF32Encoding u32BeBom = new UTF32Encoding( true, true ); // Display the preamble for each instance. PrintHexBytes( u32LeNone.GetPreamble() ); PrintHexBytes( u32BeNone.GetPreamble() ); PrintHexBytes( u32LeBom.GetPreamble() ); PrintHexBytes( u32BeBom.GetPreamble() ); } public static void PrintHexBytes( byte[] bytes ) { if (( bytes == null ) || ( bytes.Length == 0 )) Console.WriteLine( "<none>" ); else { for ( int i = 0; i < bytes.Length; i++ ) Console.Write( "{0:X2} ", bytes[i] ); Console.WriteLine(); } } } /* This code produces the following output. <none> <none> FF FE 00 00 00 00 FE FF */
using namespace System; using namespace System::Text; void PrintHexBytes( array<Byte>^bytes ); int main() { // Create instances of UTF32Encoding, with the byte order mark and without. UTF32Encoding ^ u32LeNone = gcnew UTF32Encoding; UTF32Encoding ^ u32BeNone = gcnew UTF32Encoding( true,false ); UTF32Encoding ^ u32LeBom = gcnew UTF32Encoding( false,true ); UTF32Encoding ^ u32BeBom = gcnew UTF32Encoding( true,true ); // Display the preamble for each instance. PrintHexBytes( u32LeNone->GetPreamble() ); PrintHexBytes( u32BeNone->GetPreamble() ); PrintHexBytes( u32LeBom->GetPreamble() ); PrintHexBytes( u32BeBom->GetPreamble() ); } void PrintHexBytes( array<Byte>^bytes ) { if ( (bytes == nullptr) || (bytes->Length == 0) ) Console::WriteLine( "<none>" ); else { for ( int i = 0; i < bytes->Length; i++ ) Console::Write( "{0:X2} ", bytes[ i ] ); Console::WriteLine(); } } /* This code produces the following output. <none> <none> FF FE 00 00 00 00 FE FF */
import System.*; import System.Text.*; public class SamplesUTF32Encoding { public static void main(String[] args) { // Create instances of UTF32Encoding, with the byte // order mark and without. UTF32Encoding u32LeNone = new UTF32Encoding(); UTF32Encoding u32BeNone = new UTF32Encoding(true, false); UTF32Encoding u32LeBom = new UTF32Encoding(false, true); UTF32Encoding u32BeBom = new UTF32Encoding(true, true); // Display the preamble for each instance. PrintHexBytes(u32LeNone.GetPreamble()); PrintHexBytes(u32BeNone.GetPreamble()); PrintHexBytes(u32LeBom.GetPreamble()); PrintHexBytes(u32BeBom.GetPreamble()); } //main public static void PrintHexBytes(ubyte bytes[]) { if(bytes == null || bytes.length == 0) { Console.WriteLine("<none>"); } else { for(int i = 0; i < bytes.length; i++) { Console.Write("{0:X2} ", ((System.Byte)bytes[i]).ToString("X2")); } Console.WriteLine(); } } //PrintHexBytes } //SamplesUTF32Encoding /* This code produces the following output. FF FE 00 00 <none> FF FE 00 00 00 00 FE FF */

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


UTF32Encoding コンストラクタ

名前 | 説明 |
---|---|
UTF32Encoding () | UTF32Encoding クラスの新しいインスタンスを初期化します。 |
UTF32Encoding (Boolean, Boolean) | UTF32Encoding クラスの新しいインスタンスを初期化します。パラメータでは、ビッグ エンディアン バイト順を使用するかどうか、および Unicode バイト順マークを付加するかどうかを指定します。 |
UTF32Encoding (Boolean, Boolean, Boolean) | UTF32Encoding クラスの新しいインスタンスを初期化します。パラメータでは、ビッグ エンディアン バイト順を使用するかどうか、Unicode バイト順マークを付加するかどうか、および無効なエンコーディングを検出したときに例外をスローするかどうかを指定します。 |

UTF32Encoding プロパティ


UTF32Encoding メソッド


UTF32Encoding メンバ
Unicode 文字の UTF-32 エンコーディングを表します。
UTF32Encoding データ型で公開されるメンバを以下の表に示します。




Weblioに収録されているすべての辞書からUTF32Encodingを検索する場合は、下記のリンクをクリックしてください。

- UTF32Encodingのページへのリンク