UTF7Encoding.GetChars メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
バイトシーケンスを文字のセットにデコードします。
オーバーロード
| 名前 | 説明 |
|---|---|
| GetChars(Byte*, Int32, Char*, Int32) |
指定したバイト ポインターから始まるバイト シーケンスを、指定した文字ポインターから始めて格納される文字のセットにデコードします。 |
| GetChars(Byte[], Int32, Int32, Char[], Int32) |
指定したバイト配列から指定した文字配列にバイト シーケンスをデコードします。 |
GetChars(Byte*, Int32, Char*, Int32)
重要
この API は CLS 準拠ではありません。
指定したバイト ポインターから始まるバイト シーケンスを、指定した文字ポインターから始めて格納される文字のセットにデコードします。
public:
override int GetChars(System::Byte* bytes, int byteCount, char* chars, int charCount);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public override int GetChars(byte* bytes, int byteCount, char* chars, int charCount);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetChars(byte* bytes, int byteCount, char* chars, int charCount);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetChars(byte* bytes, int byteCount, char* chars, int charCount);
[System.CLSCompliant(false)]
public override int GetChars(byte* bytes, int byteCount, char* chars, int charCount);
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int
パラメーター
- bytes
- Byte*
デコードする最初のバイトへのポインター。
- byteCount
- Int32
デコードするバイト数。
- chars
- Char*
結果の文字セットの書き込みを開始する位置へのポインター。
- charCount
- Int32
書き込む最大文字数。
返品
charsによって示される場所に書き込まれた実際の文字数。
- 属性
例外
byteCount または charCount が 0 未満です。
charCount は、結果の文字数よりも少なくなります。
フォールバックが発生しました (詳細については、「 .NET での文字エンコード」を参照してください)
および
DecoderFallback は DecoderExceptionFallback に設定されます。
注釈
結果の文字を格納するために GetChars に必要な正確な配列サイズを計算するには、 GetCharCountを使用します。 配列の最大サイズを計算するには、アプリケーションで GetMaxCharCountを使用する必要があります。 一般に、 GetCharCount メソッドではメモリの割り当てが少なくなりますが、 GetMaxCharCount メソッドの実行速度は一般的に速くなります。
ストリームから読み取られたデータなど、変換するデータは、シーケンシャル ブロックでのみ使用できます。 この場合、またはデータの量が非常に大きくて小さいブロックに分割する必要がある場合、アプリケーションでは、GetDecoder メソッドまたは GetEncoder メソッドによって提供されるDecoderまたはEncoderをそれぞれ使用する必要があります。
Note
UTF7Encoding はエラー検出を提供しません。 無効なバイトが検出されると、通常、 UTF7Encoding は無効なバイトを出力します。 バイトが 16 進数の0x7Fより大きい場合、バイト値は Unicode 文字にゼロ拡張され、結果は chars 配列に格納され、シフト シーケンスはすべて終了します。 たとえば、エンコードするバイトが 16 進数0x81の場合、結果の文字は U+0081 になります。 セキュリティ上の理由から、アプリケーションは UTF8Encoding、 UnicodeEncoding、または UTF32Encoding を使用してエラー検出を有効にすることをお勧めします。
こちらもご覧ください
- GetCharCount(Byte[], Int32, Int32)
- GetMaxCharCount(Int32)
- GetDecoder()
- GetString(Byte[], Int32, Int32)
適用対象
GetChars(Byte[], Int32, Int32, Char[], Int32)
指定したバイト配列から指定した文字配列にバイト シーケンスをデコードします。
public:
override int GetChars(cli::array <System::Byte> ^ bytes, int byteIndex, int byteCount, cli::array <char> ^ chars, int charIndex);
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex);
override this.GetChars : byte[] * int * int * char[] * int -> int
Public Overrides Function GetChars (bytes As Byte(), byteIndex As Integer, byteCount As Integer, chars As Char(), charIndex As Integer) As Integer
パラメーター
- bytes
- Byte[]
デコードするバイトシーケンスを含むバイト配列。
- byteIndex
- Int32
デコードする最初のバイトのインデックス。
- byteCount
- Int32
デコードするバイト数。
- chars
- Char[]
結果の文字セットを格納する文字配列。
- charIndex
- Int32
結果の文字セットの書き込みを開始する位置のインデックス。
返品
charsに書き込まれた実際の文字数。
例外
byteIndex または byteCount または charIndex が 0 未満です。
-または-
byteIndex および byteCount は、 bytes内の有効な範囲を示していません。
-または-
charIndex は、 charsの有効なインデックスではありません。
chars は、 charIndex から配列の末尾まで、結果の文字を格納するのに十分な容量がありません。
フォールバックが発生しました (詳細については、「 .NET での文字エンコード」を参照してください)
および
DecoderFallback は DecoderExceptionFallback に設定されます。
例
次のコード例では、 GetChars メソッドを使用してバイト配列内の要素の範囲をデコードし、結果を文字配列に格納する方法を示します。
using System;
using System.Text;
class UTF7EncodingExample {
public static void Main() {
Char[] chars;
Byte[] bytes = new Byte[] {
85, 84, 70, 55, 32, 69, 110,
99, 111, 100, 105, 110, 103, 32,
69, 120, 97, 109, 112, 108, 101
};
UTF7Encoding utf7 = new UTF7Encoding();
int charCount = utf7.GetCharCount(bytes, 2, 8);
chars = new Char[charCount];
int charsDecodedCount = utf7.GetChars(bytes, 2, 8, chars, 0);
Console.WriteLine(
"{0} characters used to decode bytes.", charsDecodedCount
);
Console.Write("Decoded chars: ");
foreach (Char c in chars) {
Console.Write("[{0}]", c);
}
Console.WriteLine();
}
}
Imports System.Text
Class UTF7EncodingExample
Public Shared Sub Main()
Dim chars() As Char
Dim bytes() As Byte = { _
85, 84, 70, 55, 32, 69, 110, _
99, 111, 100, 105, 110, 103, 32, _
69, 120, 97, 109, 112, 108, 101 _
}
Dim utf7 As New UTF7Encoding()
Dim charCount As Integer = utf7.GetCharCount(bytes, 2, 8)
chars = New Char(charCount - 1) {}
Dim charsDecodedCount As Integer = utf7.GetChars(bytes, 2, 8, chars, 0)
Console.WriteLine("{0} characters used to decode bytes.", charsDecodedCount)
Console.Write("Decoded chars: ")
Dim c As Char
For Each c In chars
Console.Write("[{0}]", c)
Next c
Console.WriteLine()
End Sub
End Class
注釈
結果の文字を格納するために GetChars に必要な正確な配列サイズを計算するには、 GetCharCountを使用します。 配列の最大サイズを計算するには、アプリケーションで GetMaxCharCountを使用する必要があります。 一般に、 GetCharCount メソッドではメモリの割り当てが少なくなりますが、 GetMaxCharCount メソッドの実行速度は一般的に速くなります。
ストリームから読み取られたデータなど、変換するデータは、シーケンシャル ブロックでのみ使用できます。 この場合、またはデータの量が非常に大きくて小さいブロックに分割する必要がある場合、アプリケーションでは、GetDecoder メソッドまたは GetEncoder メソッドによって提供されるDecoderまたはEncoderをそれぞれ使用する必要があります。
Note
UTF7Encoding はエラー検出を提供しません。 無効なバイトが検出されると、通常、 UTF7Encoding は無効なバイトを出力します。 バイトが 16 進数の0x7Fより大きい場合、バイト値は Unicode 文字にゼロ拡張され、結果は chars 配列に格納され、シフト シーケンスはすべて終了します。 たとえば、エンコードするバイトが 16 進数0x81の場合、結果の文字は U+0081 になります。 セキュリティ上の理由から、アプリケーションは UTF8Encoding、 UnicodeEncoding、または UTF32Encoding を使用してエラー検出を有効にすることをお勧めします。
こちらもご覧ください
- GetCharCount(Byte[], Int32, Int32)
- GetMaxCharCount(Int32)
- GetDecoder()
- GetString(Byte[], Int32, Int32)