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보다 작습니다.

또는 indexcountbytes에서 올바른 범위를 나타내지 않습니다.

대체가 발생했습니다(자세한 내용은 .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??ß

설명

스트림에서 읽은 데이터와 같이 변환할 데이터는 순차적 블록에서만 사용할 수 있습니다. 이 경우 애플리케이션 데이터의 양이 너무 커서 작은 블록으로 나눌 필요가 있는 경우를 사용 해야 합니다 Decoder 또는 Encoder 제공한를 GetDecoder 메서드 또는 GetEncoder 메서드를 각각.

참고

UTF7Encoding 오류 검색을 제공하지 않습니다. 잘못된 바이트가 발견되면 UTF7Encoding 일반적으로 잘못된 바이트를 내보낸다. 바이트가 16진수 0x7F 16진수보다 크면 바이트 값이 유니코드 문자로 0으로 확장되고 결과가 배열에 chars 저장되고 모든 시퀀스가 종료됩니다. 예를 들어 인코딩할 바이트가 16진수 0x81 경우 결과 문자는 U+0081입니다. 보안상의 이유로 애플리케이션은 사용 하는 좋습니다 UTF8Encoding, UnicodeEncoding, 또는 UTF32Encoding 오류 검색을 사용 하도록 설정 합니다.

적용 대상

추가 정보