UTF7Encoding.GetString(Byte[], Int32, Int32) メソッド

定義

バイト配列に格納されているある範囲のバイトを文字列にデコードします。

public:
 override System::String ^ GetString(cli::array <System::Byte> ^ bytes, int index, int count);
public override string GetString (byte[] bytes, int index, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public override string GetString (byte[] bytes, int index, int count);
override this.GetString : byte[] * int * int -> string
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetString : byte[] * int * int -> string
Public Overrides Function GetString (bytes As Byte(), index As Integer, count As Integer) As String

パラメーター

bytes
Byte[]

デコード対象のバイト シーケンスが格納されたバイト配列。

index
Int32

デコードする最初のバイトのインデックス。

count
Int32

デコードするバイト数。

戻り値

String

指定したバイト シーケンスのデコード結果が格納されている String

属性

例外

bytesnull (Nothing) です。

index または count が 0 未満です。

または index および countbytes において有効な範囲を表していません。

フォールバックが発生しました (詳細については、「 .NET での文字エンコード」を参照してください)。

および DecoderFallbackDecoderExceptionFallback に設定されます。

次のコード例では、文字列をバイト配列にエンコードし、バイトを文字列にデコードします。

using namespace System;
using namespace System::Text;
int main()
{
   
   // Create an instance of UTF7Encoding.
   UTF7Encoding^ u7 = gcnew UTF7Encoding( true );
   
   // 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 = "za\u0306\u01FD\u03B2";
   
   // Encode the string.
   array<Byte>^myBArr = gcnew array<Byte>(u7->GetByteCount( myStr ));
   u7->GetBytes( myStr, 0, myStr->Length, myBArr, 0 );
   
   // Decode the byte array.
   Console::WriteLine( "The new string is: {0}", u7->GetString( myBArr, 0, myBArr->Length ) );
}

/*
This code produces the following output.  The question marks take the place of characters that cannot be displayed at the console.

The new string is: za??

*/
using System;
using System.Text;

public class SamplesUTF7Encoding  {

   public static void Main()  {

      // Create an instance of UTF7Encoding.
      UTF7Encoding u7 = new UTF7Encoding( true );

      // 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 = "za\u0306\u01FD\u03B2";

      // Encode the string.
      byte[] myBArr = new byte[u7.GetByteCount( myStr )];
      u7.GetBytes( myStr, 0, myStr.Length, myBArr, 0 );

      // Decode the byte array.
      Console.WriteLine( "The new string is: {0}", u7.GetString( myBArr, 0, myBArr.Length ) );
   }
}


/*
This code produces the following output.  The question marks take the place of characters that cannot be displayed at the console.

The new string is: za??

*/
Imports System.Text

Public Class SamplesUTF7Encoding

   Public Shared Sub Main()

      ' Create an instance of UTF7Encoding.
      Dim u7 As New UTF7Encoding(True)

      ' 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)
      Dim myStr As String = "za" & ChrW(&H0306) & ChrW(&H01FD) & ChrW(&H03B2)

      ' Encode the string.
      Dim myBArr(u7.GetByteCount(myStr)) As Byte
      u7.GetBytes(myStr, 0, myStr.Length, myBArr, 0)

      ' Decode the byte array.
      Console.WriteLine("The new string is: {0}", u7.GetString(myBArr, 0, myBArr.Length))

   End Sub

End Class


'This code produces the following output.  The question marks take the place of characters that cannot be displayed at the console.
'
'The new string is: za??ß

注釈

ストリームから読み取られたデータなど、変換するデータは、シーケンシャル ブロックでのみ使用できます。 この場合、またはデータの量が非常に大きい場合は、より小さなブロックに分割する必要があります。アプリケーションは、それぞれメソッドまたはメソッドによって提供されるGetDecoderデータをEncoder使用DecoderするGetEncoder必要があります。

注意

UTF7Encoding はエラー検出を提供しません。 無効なバイトが見つかった場合、通常は UTF7Encoding 無効なバイトを出力します。 バイトが 16 進数の0x7Fより大きい場合、バイト値は Unicode 文字にゼロ拡張され、結果は配列に chars 格納され、シフト シーケンスは終了します。 たとえば、エンコードするバイトが 16 進数の0x81の場合、結果の文字は U+ 0081 になります。 セキュリティ上の理由から、アプリケーションでは、エラー検出を使用UTF8EncodingUnicodeEncodingまたはUTF32Encoding有効にすることをお勧めします。

適用対象

こちらもご覧ください