バイト配列内の、指定した範囲の要素を String に変換します。
Overrides Overloads Public Function GetString( _
ByVal bytes() As Byte, _ ByVal byteIndex As Integer, _ ByVal byteCount As Integer _) As String
[C#]
public override string GetString(byte[] bytes,intbyteIndex,intbyteCount);
[C++]
public: String* GetString(unsigned charbytes __gc[],intbyteIndex,intbyteCount);
[JScript]
public override function GetString(
bytes : Byte[],byteIndex : int,byteCount : int) : String;
パラメータ
- bytes
バイト配列。 - byteIndex
変換する bytes 内の最初の位置のインデックス。 - byteCount
変換するバイト数。
戻り値
bytes 内の byteIndex から byteIndex + byteCount-1 までの範囲の、 ASCIIEncoding としてデコードされた値を含んでいる String 。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | bytes が null 参照 (Visual Basic では Nothing) です。 |
ArgumentOutOfRangeException | byteIndex または byteCount が 0 未満です。
または byteIndex に byteCount を加算した値が、 bytes の長さを超えています。 |
解説
bytes 配列の任意の要素で、16 進数 0x7F を超える値が、Unicode 疑問符 ('?') に変換されます。
使用例
[Visual Basic, C#, C++] GetString メソッドを使用して、バイト配列 bytes
内の要素の範囲を String String
に変換する方法を次の例に示します。
Imports System
Imports System.Text
Class ASCIIEncodingExample
Public Shared Sub Main()
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 decoded As String = ascii.GetString(bytes, 6, 8)
Console.WriteLine(decoded)
End Sub
End Class
[C#]
using System;
using System.Text;
class ASCIIEncodingExample {
public static void Main() {
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();
String decoded = ascii.GetString(bytes, 6, 8);
Console.WriteLine(decoded);
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;
int main()
{
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();
String * decoded = ascii -> GetString(bytes, 6, 8);
Console::WriteLine(decoded);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
ASCIIEncoding クラス | ASCIIEncoding メンバ | System.Text 名前空間 | ASCIIEncoding.GetString オーバーロードの一覧