UTF7Encoding.GetString(Byte[], Int32, Int32) Metódus

Definíció

Bájttartományt kódol egy bájttömbből egy sztringbe.

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éterek

bytes
Byte[]

A dekódolni kívánt bájtok sorozatát tartalmazó bájttömb.

index
Int32

A dekódolni kívánt első bájt indexe.

count
Int32

A dekódolni kívánt bájtok száma.

Válaszok

A String megadott bájtsorozat dekódolásának eredményeit tartalmazó fájl.

Attribútumok

Kivételek

bytes az null (Nothing).

index vagy count kisebb, mint nulla.

-vagy-

index és count ne jelölje az érvényes tartományt a következőben bytes: .

Hiba történt (további információ: Character Encoding in .NET).

-és-

DecoderFallback DecoderExceptionFallbackértékre van állítva.

Példák

Az alábbi példakód egy karakterláncot bájtok tömbjeként kódol, majd visszakódolja a bájtokat egy sztringbe.

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

Megjegyzések

Az átalakítandó adatok, például a streamből beolvasott adatok csak szekvenciális blokkokban érhetők el. Ebben az esetben, vagy ha az adatok mennyisége olyan nagy, hogy kisebb blokkokra kell osztani, az alkalmazásnak a Decoder metódus vagy Encoder a GetDecoder metódus által GetEncoder megadott vagy megadott adatokat kell használnia.

Note

UTF7Encoding nem biztosít hibaészlelést. Érvénytelen bájtok esetén UTF7Encoding általában az érvénytelen bájtokat bocsátja ki. Ha egy bájt nagyobb, mint a hexadecimális 0x7F, a bájt értéke 0,0-ra van kiterjesztve Unicode-karakterre, az eredmény a chars tömbben lesz tárolva, és minden műszakütemezés leáll. Ha például a kódolni kívánt bájt hexadecimális 0x81, az eredményként kapott karakter U+0081. Biztonsági okokból javasoljuk, hogy az alkalmazásokat használja UTF8Encoding, UnicodeEncodingvagy UTF32Encoding engedélyezze a hibaészlelést.

A következőre érvényes:

Lásd még