UTF7Encoding.GetString(Byte[], Int32, Int32) Méthode

Définition

Décode une plage d'octets d'un tableau d'octets en une chaîne.

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

Paramètres

bytes
Byte[]

Tableau d'octets contenant la séquence d'octets à décoder.

index
Int32

Index du premier octet à décoder.

count
Int32

Nombre d'octets à décoder.

Retours

String

String contenant les résultats du décodage de la séquence d'octets spécifiée.

Attributs

Exceptions

bytes a la valeur null (Nothing).

index ou count est inférieur à zéro.

  • ou - index et count ne désignent pas une plage valide dans bytes.

Une secours s’est produite (pour plus d’informations, consultez Encodage de caractères dans .NET).

-et- DecoderFallback a la valeur DecoderExceptionFallback.

Exemples

L’exemple de code suivant encode une chaîne dans un tableau d’octets, puis décode les octets dans une chaîne.

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

Remarques

Les données à convertir, telles que les données lues à partir d’un flux, peuvent être disponibles uniquement dans des blocs séquentiels. Dans ce cas, ou si la quantité de données est si importante qu’elle doit être divisée en blocs plus petits, l’application doit utiliser respectivement la Decoder GetDecoder méthode ou GetEncoder la Encoder méthode fournie.

Notes

UTF7Encoding ne fournit pas de détection d’erreur. Lorsque des octets non valides sont rencontrés, UTF7Encoding émet généralement les octets non valides. Si un octet est supérieur à l'0x7F hexadécimal, la valeur d’octet est étendue zéro dans un caractère Unicode, le résultat est stocké dans le chars tableau et toute séquence de décalage est arrêtée. Par exemple, si l’octet à encoder est hexadécimal 0x81, le caractère résultant est U+0081. Pour des raisons de sécurité, vos applications sont recommandées pour utiliser UTF8Encoding, UnicodeEncodingou UTF32Encoding activer la détection des erreurs.

S’applique à

Voir aussi