Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

UTF7Encoding::GetString Method (array<Byte>^, Int32, Int32)

 

Decodes a range of bytes from a byte array into a string.

Namespace:   System.Text
Assembly:  mscorlib (in mscorlib.dll)

public:
[ComVisibleAttribute(false)]
virtual String^ GetString(
	array<unsigned char>^ bytes,
	int index,
	int count
) override

Parameters

bytes
Type: array<System::Byte>^

The byte array containing the sequence of bytes to decode.

index
Type: System::Int32

The index of the first byte to decode.

count
Type: System::Int32

The number of bytes to decode.

Return Value

Type: System::String^

A String containing the results of decoding the specified sequence of bytes.

Exception Condition
ArgumentNullException

bytes is null (Nothing).

ArgumentOutOfRangeException

index or count is less than zero.

-or-

index and count do not denote a valid range in bytes.

DecoderFallbackException

A fallback occurred (see Character Encoding in the .NET Framework for fuller explanation)

-and-

DecoderFallback is set to DecoderExceptionFallback.

Data to be converted, such as data read from a stream, might be available only in sequential blocks. In this case, or if the amount of data is so large that it needs to be divided into smaller blocks, the application should use the Decoder or the Encoder provided by the GetDecoder method or the GetEncoder method, respectively.

System_CAPS_noteNote

UTF7Encoding does not provide error detection. When invalid bytes are encountered, UTF7Encoding generally emits the invalid bytes. If a byte is larger than hexadecimal 0x7F, the byte value is zero-extended into a Unicode character, the result is stored in the chars array, and any shift sequence is terminated. For example, if the byte to encode is hexadecimal 0x81, the resulting character is U+0081. For security reasons, your applications are recommended to use UTF8Encoding, UnicodeEncoding, or UTF32Encoding and enable error detection.

The following code example encodes a string into an array of bytes, and then decodes the bytes back into a string.

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

*/

Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Return to top
Show:
© 2017 Microsoft