UTF7Encoding.GetString(Byte[], Int32, Int32) Methode

Definition

Decodiert einen Bytebereich aus einem Bytearray in eine Zeichenfolge.

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

Parameter

bytes
Byte[]

Das Bytearray, das die zu decodierende Bytefolge enthält.

index
Int32

Der Index des ersten zu decodierenden Bytes.

count
Int32

Die Anzahl der zu decodierenden Bytes.

Gibt zurück

Eine String-Klasse, die die Ergebnisse der Decodierung der angegebenen Bytefolge enthält.

Attribute

Ausnahmen

bytes ist null(Nothing).

index oder count ist kleiner als 0.

- oder -

index und count geben keinen gültigen Bereich in bytes an.

Ein Fallback ist aufgetreten (weitere Informationen finden Sie unter Zeichencodierung in .NET).

- und -

Für DecoderFallback ist DecoderExceptionFallback festgelegt.

Beispiele

Im folgenden Codebeispiel wird eine Zeichenfolge in ein Bytearray codiert und die Bytes dann wieder in eine Zeichenfolge decodiert.

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??ß

Hinweise

Zu konvertierende Daten, z. B. Daten, die aus einem Stream gelesen werden, sind möglicherweise nur in sequenziellen Blöcken verfügbar. In diesem Fall oder wenn die Menge der Daten so umfangreich ist, dass er in kleinere Blöcke aufgeteilt werden muss, sollte die Anwendung verwenden die Decoder oder die Encoder gebotenen der GetDecoder Methode oder die GetEncoder Methode bzw.

Hinweis

UTF7Encoding bietet keine Fehlererkennung. Wenn ungültige Bytes gefunden werden, UTF7Encoding gibt im Allgemeinen die ungültigen Bytes aus. Wenn ein Byte größer als hexadezimal 0x7F ist, wird der Bytewert null in ein Unicode-Zeichen erweitert, das Ergebnis wird im chars Array gespeichert, und jede Schichtsequenz wird beendet. Wenn das zu codierende Byte beispielsweise hexadezimal 0x81 ist, lautet das resultierende Zeichen U+0081. Aus Sicherheitsgründen wird empfohlen, dass Ihre Anwendungen , UnicodeEncodingoder UTF32Encoding verwenden UTF8Encodingund die Fehlererkennung aktivieren.

Gilt für:

Weitere Informationen