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

Definitie

Decodeert een bereik van bytes van een bytematrix in een tekenreeks.

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

Parameters

bytes
Byte[]

De bytematrix met de reeks bytes die moet worden gedecodeerd.

index
Int32

De index van de eerste byte om te decoderen.

count
Int32

Het aantal bytes dat moet worden gedecodeerd.

Retouren

Een String met de resultaten van het decoderen van de opgegeven reeks bytes.

Kenmerken

Uitzonderingen

bytes is null (Nothing).

index of count kleiner is dan nul.

– of –

index en count geef geen geldig bereik aan in bytes.

Er is een terugval opgetreden (zie Character Encoding in .NET).

en

DecoderFallback is ingesteld op DecoderExceptionFallback.

Voorbeelden

In het volgende codevoorbeeld wordt een tekenreeks gecodeerd in een matrix van bytes en worden de bytes vervolgens weer in een tekenreeks gedecodeerd.

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

Opmerkingen

Gegevens die moeten worden geconverteerd, zoals gegevens die uit een stroom worden gelezen, zijn mogelijk alleen in opeenvolgende blokken beschikbaar. In dit geval, of als de hoeveelheid gegevens zo groot is dat deze moet worden onderverdeeld in kleinere blokken, moet de toepassing respectievelijk de Decoder door de GetDecoder methode of de methode opgegeven methode Encoder of de GetEncoder methode gebruiken.

Note

UTF7Encoding biedt geen foutdetectie. Wanneer er ongeldige bytes worden aangetroffen, UTF7Encoding worden over het algemeen de ongeldige bytes verzonden. Als een byte groter is dan hexadecimaal 0x7F, wordt de bytewaarde nul uitgebreid in een Unicode-teken, wordt het resultaat opgeslagen in de chars matrix en wordt elke shiftreeks beëindigd. Als de byte om te coderen bijvoorbeeld hexadecimaal is 0x81, is het resulterende teken U+0081. Om veiligheidsredenen worden uw toepassingen aanbevolen om foutdetectie te gebruiken UTF8Encoding, UnicodeEncodingof UTF32Encoding in te schakelen.

Van toepassing op

Zie ook