Decoder.Convert 方法

定义

将已编码的字节序列转换为字符串或字符数组。

重载

Convert(ReadOnlySpan<Byte>, Span<Char>, Boolean, Int32, Int32, Boolean)

将编码字节的范围转换为 UTF-16 编码字符,并将结果存储在另一个范围缓冲区中。

Convert(Byte*, Int32, Char*, Int32, Boolean, Int32, Int32, Boolean)

将编码字节的缓冲区转换为 UTF-16 编码字符,并将结果存储在另一个缓冲区中。

Convert(Byte[], Int32, Int32, Char[], Int32, Int32, Boolean, Int32, Int32, Boolean)

将编码字节的数组转换为 UTF-16 编码字符,并将结果存储在字符数组中。

注解

请记住, 对象在 Decoder 调用 Convert之间保存状态。 当应用程序完成数据流时,它应将 参数设置为 flushtrue 以确保刷新状态信息。 使用此设置时,解码器会忽略数据块末尾的无效字节,并清除内部缓冲区。 作为逻辑单元一部分的任何剩余已处理数据(例如代理项对的高代理项)将根据当前的回退设置进行转换。

方法 Convert 旨在用于在循环中解码任意数量的输入,例如从文件或流中读取的数据。 它将解码操作的输出存储在固定大小的缓冲区中。 GetChars 如果输出缓冲区不够大,则会引发异常,但 Convert 会尽可能多地填充空间,并返回读取的字节和写入的字符,前提是输出数组允许至少两个字符。 另请参阅 Encoding.GetChars 以获取更多评论。

Convert(ReadOnlySpan<Byte>, Span<Char>, Boolean, Int32, Int32, Boolean)

Source:
Decoder.cs
Source:
Decoder.cs
Source:
Decoder.cs

将编码字节的范围转换为 UTF-16 编码字符,并将结果存储在另一个范围缓冲区中。

public:
 virtual void Convert(ReadOnlySpan<System::Byte> bytes, Span<char> chars, bool flush, [Runtime::InteropServices::Out] int % bytesUsed, [Runtime::InteropServices::Out] int % charsUsed, [Runtime::InteropServices::Out] bool % completed);
public virtual void Convert (ReadOnlySpan<byte> bytes, Span<char> chars, bool flush, out int bytesUsed, out int charsUsed, out bool completed);
abstract member Convert : ReadOnlySpan<byte> * Span<char> * bool * int * int * bool -> unit
override this.Convert : ReadOnlySpan<byte> * Span<char> * bool * int * int * bool -> unit
Public Overridable Sub Convert (bytes As ReadOnlySpan(Of Byte), chars As Span(Of Char), flush As Boolean, ByRef bytesUsed As Integer, ByRef charsUsed As Integer, ByRef completed As Boolean)

参数

bytes
ReadOnlySpan<Byte>

包含要转换的序列的只读字节范围。

chars
Span<Char>

用于存储转换后的字符的范围。

flush
Boolean

如果没有更多的数据要进行转换,则为 true;否则为 false

bytesUsed
Int32

当此方法返回时,包含由转换生成的字节数。 此参数未经初始化即被传递。

charsUsed
Int32

当此方法返回时,包含来自在转换中使用的 chars 的字符数。 此参数未经初始化即被传递。

completed
Boolean

此方法返回时,如果转换了所有指定的字符,则包含 true;否则包含 false。 此参数未经初始化即被传递。

注解

输出 completed 参数指示输入字节范围中的所有数据是否已转换并存储在字符范围中。 如果在不超出字符范围中的字符数的情况下,无法转换输入字节范围中包含的字节数,则此参数设置为 false 。 在这种情况下,应用程序应使用输出缓冲区的内容或提供新的输出缓冲区,按 参数指定的bytesUsed字节数递增bytes参数,然后再次调用 Convert 方法来处理剩余输入。

参数 completed 也可以设置为 false,即使 bytesUsed 参数和字节范围长度相等。 如果对象中 Decoder 仍有数据尚未存储在跨度中 bytes ,则会出现这种情况。

适用于

Convert(Byte*, Int32, Char*, Int32, Boolean, Int32, Int32, Boolean)

Source:
Decoder.cs
Source:
Decoder.cs
Source:
Decoder.cs

将编码字节的缓冲区转换为 UTF-16 编码字符,并将结果存储在另一个缓冲区中。

public:
 virtual void Convert(System::Byte* bytes, int byteCount, char* chars, int charCount, bool flush, [Runtime::InteropServices::Out] int % bytesUsed, [Runtime::InteropServices::Out] int % charsUsed, [Runtime::InteropServices::Out] bool % completed);
[System.CLSCompliant(false)]
public virtual void Convert (byte* bytes, int byteCount, char* chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public virtual void Convert (byte* bytes, int byteCount, char* chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
[System.Security.SecurityCritical]
public virtual void Convert (byte* bytes, int byteCount, char* chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed);
[<System.CLSCompliant(false)>]
abstract member Convert : nativeptr<byte> * int * nativeptr<char> * int * bool * int * int * bool -> unit
override this.Convert : nativeptr<byte> * int * nativeptr<char> * int * bool * int * int * bool -> unit
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member Convert : nativeptr<byte> * int * nativeptr<char> * int * bool * int * int * bool -> unit
override this.Convert : nativeptr<byte> * int * nativeptr<char> * int * bool * int * int * bool -> unit
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Security.SecurityCritical>]
abstract member Convert : nativeptr<byte> * int * nativeptr<char> * int * bool * int * int * bool -> unit
override this.Convert : nativeptr<byte> * int * nativeptr<char> * int * bool * int * int * bool -> unit

参数

bytes
Byte*

包含要转换的字节序列的缓冲区的地址。

byteCount
Int32

bytes 中要转换的字节数。

chars
Char*

用于存储已转换的字符的缓冲区的地址。

charCount
Int32

要在转换中使用的 chars 中的最大字符数。

flush
Boolean

如果没有更多的数据要进行转换,则为 true;否则为 false

bytesUsed
Int32

当此方法返回时,包含由转换生成的字节数。 此参数未经初始化即被传递。

charsUsed
Int32

当此方法返回时,包含来自在转换中使用的 chars 的字符数。 此参数未经初始化即被传递。

completed
Boolean

当此方法返回时,如果转换了所有由 byteCount 指定的字符,则包含 true;否则包含 false。 此参数未经初始化即被传递。

属性

例外

charsbytesnull (Nothing)。

charCountbyteCount 小于零。

输出缓冲区太小,无法包含任何已转换的输出。 输出缓冲区的大小至少应为 2 个字符,以容纳至少一个代理项字符对。

发生回退(有关详细信息,请参阅采用 .NET 的字符编码

-和-

Fallback 设置为 DecoderExceptionFallback

注解

输出 completed 参数指示输入缓冲区中的所有数据是否已转换并存储在输出缓冲区中。 如果参数指定的字节数不能在超过参数指定的byteCount字符charCount数的情况下转换,则此参数设置为 false 。 在这种情况下,应用程序应使用输出缓冲区的内容或提供新的输出缓冲区,按 参数指定的bytesUsed字节数递增bytes参数,然后再次调用 Convert 方法来处理剩余输入。

参数 completed 也可以设置为 false,即使 bytesUsedbyteCount 参数相等。 如果对象中 Decoder 仍有尚未存储在缓冲区中的数据 bytes ,则会出现这种情况。

适用于

Convert(Byte[], Int32, Int32, Char[], Int32, Int32, Boolean, Int32, Int32, Boolean)

Source:
Decoder.cs
Source:
Decoder.cs
Source:
Decoder.cs

将编码字节的数组转换为 UTF-16 编码字符,并将结果存储在字符数组中。

public:
 virtual void Convert(cli::array <System::Byte> ^ bytes, int byteIndex, int byteCount, cli::array <char> ^ chars, int charIndex, int charCount, bool flush, [Runtime::InteropServices::Out] int % bytesUsed, [Runtime::InteropServices::Out] int % charsUsed, [Runtime::InteropServices::Out] bool % completed);
public virtual void Convert (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual void Convert (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed);
abstract member Convert : byte[] * int * int * char[] * int * int * bool * int * int * bool -> unit
override this.Convert : byte[] * int * int * char[] * int * int * bool * int * int * bool -> unit
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member Convert : byte[] * int * int * char[] * int * int * bool * int * int * bool -> unit
override this.Convert : byte[] * int * int * char[] * int * int * bool * int * int * bool -> unit
Public Overridable Sub Convert (bytes As Byte(), byteIndex As Integer, byteCount As Integer, chars As Char(), charIndex As Integer, charCount As Integer, flush As Boolean, ByRef bytesUsed As Integer, ByRef charsUsed As Integer, ByRef completed As Boolean)

参数

bytes
Byte[]

要转换的字节数组。

byteIndex
Int32

要转换的 bytes 的第一个元素。

byteCount
Int32

要转换的 bytes 的元素数。

chars
Char[]

用于存储转换后的字符的数组。

charIndex
Int32

存储数据的 chars 的第一个元素。

charCount
Int32

要在转换中使用的 chars 的元素的最大数量。

flush
Boolean

如果没有更多的数据要进行转换,则为 true;否则为 false

bytesUsed
Int32

当此方法返回时,包含在转换中使用的字节数。 此参数未经初始化即被传递。

charsUsed
Int32

当此方法返回时,包含由转换生成的 chars 中的字符数。 此参数未经初始化即被传递。

completed
Boolean

当此方法返回时,如果转换了所有由 byteCount 指定的字符,则包含 true;否则包含 false。 此参数未经初始化即被传递。

属性

例外

charsbytesnull (Nothing)。

charIndexcharCountbyteIndexbyteCount 小于零。

chars - charIndex 的长度小于 charCount

bytes - byteIndex 的长度小于 byteCount

输出缓冲区太小,无法包含任何已转换的输出。 输出缓冲区的大小至少应为 2 个字符,以容纳至少一个代理项字符对。

发生回退(有关详细信息,请参阅采用 .NET 的字符编码

-和-

Fallback 设置为 DecoderExceptionFallback

示例

以下示例使用 Convert 方法将 UTF-16 字符的文件转换为 UTF-8。 然后, Convert 它使用 方法将 UTF-8 字符转换回 UTF-16 字符。

// This code example demonstrates the Encoder.Convert() and Decoder.Convert methods.
// This example uses files for input and output, but any source that can be expressed
// as a stream can be used instead.

    using System;
    using System.Text;
    using System.IO;

    public class Sample
    {
    static void Main(string[] args)
        {
// Create a large file of UTF-16 encoded Unicode characters. The file is named Example.txt,
// and is used as input to the Encoder.Convert() method.

            CreateTestFile("Example.txt");

// Using an input file of UTF-16 encoded characters named Example.txt, create an output file
// of UTF-8 encoded bytes named UTF8.txt.

            EncoderConvert("Example.txt", "UTF8.txt", Encoding.UTF8);

// Using an input file of UTF-8 encoded bytes named UTF8.txt, create an output file
// of UTF-16 encoded characters named UTF16.txt.

            DecoderConvert("UTF8.txt", "UTF16.txt", Encoding.UTF8);
        }

// --------------------------------------------------------------------------------------------
// Use the Encoder.Convert() method to convert a file of characters to a file of encoded bytes.
// --------------------------------------------------------------------------------------------
        static void EncoderConvert(String inputFileName, String outputFileName, Encoding enc)
        {
// Convert an input file of characters to an output file of encoded bytes.
// StreamWriter could convert the input file for us, but we'll perform the conversion
// ourselves.

            FileStream fs = new FileStream(outputFileName, FileMode.Create);
            BinaryWriter outputFile = new BinaryWriter(fs);

// StreamReader will detect Unicode encoding from the Byte Order Mark that heads the input file.
            StreamReader inputFile = new StreamReader(inputFileName);

// Get an Encoder.
            Encoder encoder = enc.GetEncoder();

// Guarantee the output buffer large enough to convert a few characters.
            int UseBufferSize = 64;
            if (UseBufferSize < enc.GetMaxByteCount(10))
                    UseBufferSize = enc.GetMaxByteCount(10);
            byte[] bytes = new byte[UseBufferSize];

// Intentionally make the input character buffer larger than the output byte buffer so the
// conversion loop executes more than one cycle.

            char[] chars = new char[UseBufferSize * 4];
            int charsRead;
            do
            {
// Read at most the number of characters that will fit in the input buffer. The return
// value is the actual number of characters read, or zero if no characters remain.
                charsRead = inputFile.Read(chars, 0, UseBufferSize * 4);

                bool completed = false;
                int charIndex = 0;
                int charsUsed;
                int bytesUsed;

                while (!completed)
                {
// If this is the last input data, flush the encoder's internal buffer and state.

                    bool flush = (charsRead == 0);
                    encoder.Convert(chars, charIndex, charsRead - charIndex,
                                    bytes, 0, UseBufferSize, flush,
                                    out charsUsed, out bytesUsed, out completed);

// The conversion produced the number of bytes indicated by bytesUsed. Write that number
// of bytes to the output file.
                    outputFile.Write(bytes, 0, bytesUsed);

// Increment charIndex to the next block of characters in the input buffer, if any, to convert.
                    charIndex += charsUsed;
                }
            }
            while(charsRead != 0);

            outputFile.Close();
            fs.Close();
            inputFile.Close();
        }

// --------------------------------------------------------------------------------------------
// Use the Decoder.Convert() method to convert a file of encoded bytes to a file of characters.
// --------------------------------------------------------------------------------------------
        static void DecoderConvert(String inputFileName, String outputFileName, Encoding enc)
        {
// Convert an input file of of encoded bytes to an output file characters.
// StreamWriter could convert the input file for us, but we'll perform the conversion
// ourselves.

            StreamWriter outputFile = new StreamWriter(outputFileName, false, Encoding.Unicode);

// Read the input as a binary file so we can detect the Byte Order Mark.
            FileStream fs = new FileStream(inputFileName, FileMode.Open);
            BinaryReader inputFile = new BinaryReader(fs);

// Get a Decoder.
            Decoder decoder = enc.GetDecoder();

// Guarantee the output buffer large enough to convert a few characters.
            int UseBufferSize = 64;
            if (UseBufferSize < enc.GetMaxCharCount(10))
                    UseBufferSize = enc.GetMaxCharCount(10);
            char[] chars = new char[UseBufferSize];

// Intentionally make the input byte buffer larger than the output character buffer so the
// conversion loop executes more than one cycle.

            byte[] bytes = new byte[UseBufferSize * 4];
            int bytesRead;
            do
            {
// Read at most the number of bytes that will fit in the input buffer. The
// return value is the actual number of bytes read, or zero if no bytes remain.

                bytesRead = inputFile.Read(bytes, 0, UseBufferSize * 4);

                bool completed = false;
                int byteIndex = 0;
                int bytesUsed;
                int charsUsed;

                while (!completed)
                {
// If this is the last input data, flush the decoder's internal buffer and state.

                    bool flush = (bytesRead == 0);
                    decoder.Convert(bytes, byteIndex, bytesRead - byteIndex,
                                    chars, 0, UseBufferSize, flush,
                                    out bytesUsed, out charsUsed, out completed);

// The conversion produced the number of characters indicated by charsUsed. Write that number
// of characters to the output file.

                    outputFile.Write(chars, 0, charsUsed);

// Increment byteIndex to the next block of bytes in the input buffer, if any, to convert.
                    byteIndex += bytesUsed;
                }
            }
            while(bytesRead != 0);

            outputFile.Close();
            fs.Close();
            inputFile.Close();
        }

// --------------------------------------------------------------------------------------------
// Create a large file of UTF-16 encoded Unicode characters.
// --------------------------------------------------------------------------------------------
        static void CreateTestFile(String FileName)
        {
// StreamWriter defaults to UTF-8 encoding so explicitly specify Unicode, that is,
// UTF-16, encoding.
            StreamWriter file = new StreamWriter(FileName, false, Encoding.Unicode);

// Write a line of text 100 times.
            for (int i = 0; i < 100; i++)
            {
                file.WriteLine("This is an example input file used by the convert example.");
            }

// Write Unicode characters from U+0000 to, but not including, the surrogate character range.
            for (char c = (char)0; c < (char)0xD800; c++)
            {
                file.Write(c);
            }
            file.Close();
        }
    }

/*
This code example produces the following results:

(Execute the -dir- console window command and examine the files created.)

Example.txt, which contains 122,594 bytes (61,297 UTF-16 encoded characters).
UTF8.txt, which contains 169,712 UTF-8 encoded bytes.
UTF16.txt, which contains 122,594 bytes (61,297 UTF-16 encoded characters).

(Execute the -comp- console window command and compare the two Unicode files.)

>comp example.txt utf16.txt /L
Comparing example.txt and utf16.txt...
Files compare OK

(The two files are equal.)

*/
' This code example demonstrates the Encoder.Convert() and Decoder.Convert methods. 
' This example uses files for input and output, but any source that can be expressed
' as a stream can be used instead.

Imports System.Text
Imports System.IO

Public Class Sample
    Shared Sub Main(ByVal args() As String) 
        ' Create a large file of UTF-16 encoded Unicode characters. The file is named Example.txt, 
        ' and is used as input to the Encoder.Convert() method. 
        CreateTestFile("Example.txt")
        
        
        ' Using an input file of UTF-16 encoded characters named Example.txt, create an output file 
        ' of UTF-8 encoded bytes named UTF8.txt.
        EncoderConvert("Example.txt", "UTF8.txt", Encoding.UTF8)
        
        ' Using an input file of UTF-8 encoded bytes named UTF8.txt, create an output file 
        ' of UTF-16 encoded characters named UTF16.txt.
        DecoderConvert("UTF8.txt", "UTF16.txt", Encoding.UTF8)
    
    End Sub
    
    ' --------------------------------------------------------------------------------------------
    ' Use the Encoder.Convert() method to convert a file of characters to a file of encoded bytes.
    ' --------------------------------------------------------------------------------------------
    Shared Sub EncoderConvert(ByVal inputFileName As String, ByVal outputFileName As String, ByVal enc As Encoding) 
        ' Convert an input file of characters to an output file of encoded bytes.
        ' StreamWriter could convert the input file for us, but we'll perform the conversion 
        ' ourselves.
        Dim fs As New FileStream(outputFileName, FileMode.Create)
        Dim outputFile As New BinaryWriter(fs)
        
        ' StreamReader will detect Unicode encoding from the Byte Order Mark that heads the input file.
        Dim inputFile As New StreamReader(inputFileName)
        
        ' Get an Encoder.
        Dim encoder As Encoder = enc.GetEncoder()
        
        ' Guarantee the output buffer large enough to convert a few characters.
        Dim UseBufferSize As Integer = 64
        If UseBufferSize < enc.GetMaxByteCount(10) Then
            UseBufferSize = enc.GetMaxByteCount(10)
        End If
        Dim bytes(UseBufferSize) As Byte
        
        ' Intentionally make the input character buffer larger than the output byte buffer so the 
        ' conversion loop executes more than one cycle. 
        Dim chars(UseBufferSize * 4) As Char
        Dim charsRead As Integer
        Do
            ' Read at most the number of characters that will fit in the input buffer. The return 
            ' value is the actual number of characters read, or zero if no characters remain. 
            charsRead = inputFile.Read(chars, 0, UseBufferSize * 4)
            
            Dim completed As Boolean = False
            Dim charIndex As Integer = 0
            Dim charsUsed As Integer
            Dim bytesUsed As Integer
            
            While Not completed
                ' If this is the last input data, flush the encoder's internal buffer and state.
                Dim flush As Boolean = charsRead = 0
                encoder.Convert(chars, charIndex, charsRead - charIndex, bytes, 0, UseBufferSize, flush, charsUsed, bytesUsed, completed)
                
                ' The conversion produced the number of bytes indicated by bytesUsed. Write that number
                ' of bytes to the output file.
                outputFile.Write(bytes, 0, bytesUsed)
                
                ' Increment charIndex to the next block of characters in the input buffer, if any, to convert.
                charIndex += charsUsed
            End While
        Loop While charsRead <> 0
        
        outputFile.Close()
        fs.Close()
        inputFile.Close()
    
    End Sub
    
    ' --------------------------------------------------------------------------------------------
    ' Use the Decoder.Convert() method to convert a file of encoded bytes to a file of characters.
    ' --------------------------------------------------------------------------------------------
    Shared Sub DecoderConvert(ByVal inputFileName As String, ByVal outputFileName As String, ByVal enc As Encoding) 
        ' Convert an input file of of encoded bytes to an output file characters.
        ' StreamWriter could convert the input file for us, but we'll perform the conversion 
        ' ourselves.
        Dim outputFile As New StreamWriter(outputFileName, False, Encoding.Unicode)
        
        ' Read the input as a binary file so we can detect the Byte Order Mark.
        Dim fs As New FileStream(inputFileName, FileMode.Open)
        Dim inputFile As New BinaryReader(fs)
        
        ' Get a Decoder.
        Dim decoder As Decoder = enc.GetDecoder()
        
        ' Guarantee the output buffer large enough to convert a few characters.
        Dim UseBufferSize As Integer = 64
        If UseBufferSize < enc.GetMaxCharCount(10) Then
            UseBufferSize = enc.GetMaxCharCount(10)
        End If
        Dim chars(UseBufferSize) As Char
        
        ' Intentionally make the input byte buffer larger than the output character buffer so the 
        ' conversion loop executes more than one cycle. 
        Dim bytes(UseBufferSize * 4) As Byte
        Dim bytesRead As Integer
        Do
            ' Read at most the number of bytes that will fit in the input buffer. The 
            ' return value is the actual number of bytes read, or zero if no bytes remain. 
            bytesRead = inputFile.Read(bytes, 0, UseBufferSize * 4)
            
            Dim completed As Boolean = False
            Dim byteIndex As Integer = 0
            Dim bytesUsed As Integer
            Dim charsUsed As Integer
            
            While Not completed
                ' If this is the last input data, flush the decoder's internal buffer and state.
                Dim flush As Boolean = bytesRead = 0
                decoder.Convert(bytes, byteIndex, bytesRead - byteIndex, chars, 0, UseBufferSize, flush, bytesUsed, charsUsed, completed)
                
                ' The conversion produced the number of characters indicated by charsUsed. Write that number
                ' of characters to the output file.
                outputFile.Write(chars, 0, charsUsed)
                
                ' Increment byteIndex to the next block of bytes in the input buffer, if any, to convert.
                byteIndex += bytesUsed
            End While
        Loop While bytesRead <> 0
        
        outputFile.Close()
        fs.Close()
        inputFile.Close()
    
    End Sub
    
    ' --------------------------------------------------------------------------------------------
    ' Create a large file of UTF-16 encoded Unicode characters. 
    ' --------------------------------------------------------------------------------------------
    Shared Sub CreateTestFile(ByVal FileName As String) 
        ' StreamWriter defaults to UTF-8 encoding so explicitly specify Unicode, that is, 
        ' UTF-16, encoding.
        Dim file As New StreamWriter(FileName, False, Encoding.Unicode)
        
        ' Write a line of text 100 times.
        Dim i As Integer
        For i = 0 To 99
            file.WriteLine("This is an example input file used by the convert example.")
        Next i
        
        ' Write Unicode characters from U+0000 to, but not including, the surrogate character range.
        Dim c As Integer
        For c = 0 To &HD800
            file.Write(ChrW(c))
        Next c
        file.Close()
    
    End Sub
End Class

'
'This code example produces the following results:
'
'(Execute the -dir- console window command and examine the files created.)
'
'Example.txt, which contains 122,594 bytes (61,297 UTF-16 encoded characters).
'UTF8.txt, which contains 169,712 UTF-8 encoded bytes.
'UTF16.txt, which contains 122,594 bytes (61,297 UTF-16 encoded characters).
'
'(Execute the -comp- console window command and compare the two Unicode files.)
'
'>comp example.txt utf16.txt /L
'Comparing example.txt and utf16.txt...
'Files compare OK
'
'(The two files are equal.)
'

注解

输出 completed 参数指示输入缓冲区中的所有数据是否已转换并存储在输出缓冲区中。 如果参数指定的字节数不能在超过参数指定的byteCount字符charCount数的情况下转换,则此参数设置为 false 。 在这种情况下,应用程序应使用输出缓冲区的内容或提供新的输出缓冲区,按 参数指定的bytesUsed字节数递增bytes参数,然后再次调用 Convert 方法来处理剩余输入。

参数 completed 也可以设置为 false,即使 bytesUsedbyteCount 参数相等。 如果对象中 Decoder 仍有尚未存储在缓冲区中的数据 bytes ,则会出现这种情况。

适用于