ASCIIEncoding.GetChars メソッド
バイト配列から指定した要素のセットをデコードし、その結果を Unicode 文字配列内の指定した要素のセットに格納します。
オーバーロードの一覧
バイト配列から指定した範囲の要素をデコードし、その結果を Unicode 文字配列内の指定した範囲の要素に格納します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Overrides Public Function GetChars(Byte(), Integer, Integer, Char(), Integer) As Integer
[C#] public override int GetChars(byte[], int, int, char[], int);
[C++] public: int GetChars(unsigned char __gc[], int, int, __wchar_t __gc[], int);
[JScript] public override function GetChars(Byte[], int, int, Char[], int) : int;
Encoding から継承されます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function GetChars(Byte()) As Char()
[C++] public: virtual __wchar_t GetChars(unsigned char __gc[]) __gc[];
Encoding から継承されます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function GetChars(Byte(), Integer, Integer) As Char()
[C++] public: virtual __wchar_t GetChars(unsigned char __gc[], int, int) __gc[];
[JScript] public function GetChars(Byte[], int, int) : Char[];
使用例
[Visual Basic, C#, C++] バイト配列からある範囲の要素をデコードし、その結果を Unicode 文字配列の一連の要素に格納する方法を次の例に示します。 GetCharCount メソッドは、配列 bytes
内でデコードされた要素を格納するために必要な文字数を計算するときに使用します。 GetChars メソッドは、 bytes
内の指定された要素をデコードし、その結果を新しい文字配列 chars
に格納します。
[Visual Basic, C#, C++] メモ ここでは、GetChars のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Imports System
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
[C#]
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();
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;
using namespace System::Collections;
int main()
{
Char chars[];
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 = new ASCIIEncoding();
int charCount = ascii -> GetCharCount(bytes, 6, 8);
chars = new Char[charCount];
int charsDecodedCount = ascii -> GetChars(bytes, 6, 8, chars, 0);
Console::WriteLine(S"{0} characters used to decode bytes.", __box(charsDecodedCount));
Console::Write(S"Decoded chars: ");
IEnumerator* myEnum = chars->GetEnumerator();
while (myEnum->MoveNext())
{
Char* c = __try_cast<Char*>(myEnum->Current);
Console::Write(S"[{0}]", c->ToString());
}
Console::WriteLine();
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。