ASCIIEncoding.GetChars メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
バイト シーケンスを文字のセットにデコードします。
オーバーロード
GetChars(ReadOnlySpan<Byte>, Span<Char>) |
指定されたバイト スパンを指定された文字スパンにデコードします。 |
GetChars(Byte*, Int32, Char*, Int32) |
指定したバイト ポインターで始まるバイト シーケンスを、指定した文字ポインターを開始位置として格納される文字のセットにデコードします。 |
GetChars(Byte[], Int32, Int32, Char[], Int32) |
指定したバイト配列に格納されているバイト シーケンスを指定した文字配列にデコードします。 |
GetChars(ReadOnlySpan<Byte>, Span<Char>)
指定されたバイト スパンを指定された文字スパンにデコードします。
public:
override int GetChars(ReadOnlySpan<System::Byte> bytes, Span<char> chars);
public override int GetChars (ReadOnlySpan<byte> bytes, Span<char> chars);
override this.GetChars : ReadOnlySpan<byte> * Span<char> -> int
Public Overrides Function GetChars (bytes As ReadOnlySpan(Of Byte), chars As Span(Of Char)) As Integer
パラメーター
- bytes
- ReadOnlySpan<Byte>
デコードするバイトを格納しているスパン。
戻り値
chars
に書き込まれた実際の文字数。
注釈
結果の文字を格納するために必要な正確な GetChars サイズを計算するには、次を使用します GetCharCount。 最大サイズを計算するには、次を使用します GetMaxCharCount。 メソッドは一般に、より GetCharCount 少ないメモリの割り当てを可能にしますが、 GetMaxCharCount メソッドは通常、より高速に実行されます。
ストリームから読み取られたデータなど、変換するデータは、シーケンシャル ブロックでのみ使用できます。 この場合、またはデータの量が非常に大きくて小さいブロックに分割する必要がある場合は、メソッドまたはEncoderメソッドによってGetDecoder提供されるデータをそれぞれ使用DecoderするGetEncoder必要があります。
ASCIIEncoding はエラー検出を提供しません。 16 進数 0x7F
より大きいバイトは、Unicode 疑問符 ("?") としてデコードされます。
注意事項
セキュリティ上の理由から、エラー検出を使用 UTF8Encodingするか、 UnicodeEncodingまたは UTF32Encoding 有効にする必要があります。
適用対象
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)]
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)>]
[<System.Security.SecurityCritical>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
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
パラメーター
- bytes
- Byte*
デコードする最初のバイトへのポインター。
- byteCount
- Int32
デコードするバイト数。
- chars
- Char*
結果の文字セットの書き込みを開始する位置へのポインター。
- charCount
- Int32
書き込む文字の最大数。
戻り値
chars
によって示される位置に書き込まれる実際の文字数。
- 属性
例外
byteCount
または charCount
が 0 未満です。
charCount
が結果の文字数より少なくなっています。
フォールバックが発生しました (詳細については「.NET での文字エンコード」を参照) および DecoderFallback が DecoderExceptionFallback に設定されます。
注釈
結果の文字を格納するために必要な正確な GetChars 配列サイズを計算するために、アプリケーションで使用 GetCharCountされます。 配列の最大サイズを計算するには、アプリケーションで使用 GetMaxCharCountする必要があります。 メソッドは一般に、より GetCharCount 少ないメモリの割り当てを可能にしますが、 GetMaxCharCount メソッドは通常、より高速に実行されます。
ストリームから読み取られたデータなど、変換するデータは、シーケンシャル ブロックでのみ使用できます。 この場合、またはデータの量が非常に大きくて小さなブロックに分割する必要がある場合、アプリケーションは、それぞれメソッドまたはメソッドによって提供されるGetDecoder、またはEncoder提供されるデータを使用DecoderするGetEncoder必要があります。
ASCIIEncoding はエラー検出を提供しません。 16 進数0x7Fより大きいバイトは、Unicode 疑問符 ("?") としてデコードされます。
注意事項
セキュリティ上の理由から、アプリケーションを使用 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 に設定されます。
例
次の例では、バイト配列から要素の範囲をデコードし、結果を Unicode 文字配列内の要素のセットに格納する方法を示します。
using namespace System;
using namespace System::Text;
using namespace System::Collections;
int main()
{
array<Char>^chars;
array<Byte>^bytes = {65,83,67,73,73,32,69,110,99,111,100,105,110,103,32,69,120,97,109,112,108,101};
ASCIIEncoding^ ascii = gcnew ASCIIEncoding;
int charCount = ascii->GetCharCount( bytes, 6, 8 );
chars = gcnew array<Char>(charCount);
int charsDecodedCount = ascii->GetChars( bytes, 6, 8, chars, 0 );
Console::WriteLine( "{0} characters used to decode bytes.", charsDecodedCount );
Console::Write( "Decoded chars: " );
IEnumerator^ myEnum = chars->GetEnumerator();
while ( myEnum->MoveNext() )
{
Char c = safe_cast<Char>(myEnum->Current);
Console::Write( "[{0}]", c.ToString() );
}
Console::WriteLine();
}
using System;
using System.Text;
class ASCIIEncodingExample {
public static void Main() {
Char[] chars;
Byte[] bytes = new Byte[] {
65, 83, 67, 73, 73, 32, 69,
110, 99, 111, 100, 105, 110, 103,
32, 69, 120, 97, 109, 112, 108, 101
};
ASCIIEncoding ascii = new ASCIIEncoding();
int charCount = ascii.GetCharCount(bytes, 6, 8);
chars = new Char[charCount];
int charsDecodedCount = ascii.GetChars(bytes, 6, 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 ASCIIEncodingExample
Public Shared Sub Main()
Dim chars() As Char
Dim bytes() As Byte = { _
65, 83, 67, 73, 73, 32, 69, _
110, 99, 111, 100, 105, 110, 103, _
32, 69, 120, 97, 109, 112, 108, 101}
Dim ascii As New ASCIIEncoding()
Dim charCount As Integer = ascii.GetCharCount(bytes, 6, 8)
chars = New Char(charCount - 1) {}
Dim charsDecodedCount As Integer = ascii.GetChars(bytes, 6, 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、またはEncoder提供されるデータを使用DecoderするGetEncoder必要があります。
ASCIIEncoding はエラー検出を提供しません。 16 進数0x7Fより大きいバイトは、Unicode 疑問符 ("?") としてデコードされます。
注意事項
セキュリティ上の理由から、アプリケーションを使用 UTF8Encodingするか、 UnicodeEncodingエラー UTF32Encoding 検出を有効にすることをお勧めします。
こちらもご覧ください
- GetCharCount(Byte[], Int32, Int32)
- GetMaxCharCount(Int32)
- GetDecoder()
- GetString(Byte[], Int32, Int32)