Utf8.ToUtf16(ReadOnlySpan<Byte>, Span<Char>, Int32, Int32, Boolean, Boolean) 方法
定义
将 UTF-8 编码只读字节范围转换为 UTF-16 编码字符范围。Converts a UTF-8 encoded read-only byte span to a UTF-16 encoded character span.
public static System.Buffers.OperationStatus ToUtf16 (ReadOnlySpan<byte> source, Span<char> destination, out int bytesRead, out int charsWritten, bool replaceInvalidSequences = true, bool isFinalBlock = true);
static member ToUtf16 : ReadOnlySpan<byte> * Span<char> * int * int * bool * bool -> System.Buffers.OperationStatus
Public Shared Function ToUtf16 (source As ReadOnlySpan(Of Byte), destination As Span(Of Char), ByRef bytesRead As Integer, ByRef charsWritten As Integer, Optional replaceInvalidSequences As Boolean = true, Optional isFinalBlock As Boolean = true) As OperationStatus
参数
- source
- ReadOnlySpan<Byte>
UTF-8 编码只读字节范围。A UTF-8 encoded read-only byte span.
- bytesRead
- Int32
方法返回时,从 source 中读取的字节数。When the method returns, the number of bytes read from source.
- charsWritten
- Int32
方法返回时,写入 destination 的字符数。When the method returns, the number of characters written to destination.
- replaceInvalidSequences
- Boolean
若要将 source 中的无效 UTF-8 序列替换为 U+FFFD,则为 true;若要返回 InvalidData(如果在 source 中发现了无效字符),则为 false。true to replace invalid UTF-8 sequences in source with U+FFFD; false to return InvalidData if invalid characters are found in source.
- isFinalBlock
- Boolean
如果方法不应返回 NeedMoreData,则为 true;否则为 false。true if the method should not return NeedMoreData; otherwise, false.
返回
一个指示转换状态的值。A value that indicates the status of the conversion.
注解
此方法对应于UTF8Encoding方法,但它具有不同的调用约定、不同的错误处理机制和不同的性能特征。This method corresponds to the UTF8Encoding.GetChars method, except that it has a different calling convention, different error handling mechanisms, and different performance characteristics.
如果 "replaceInvalidSequences" 为 true ,则该方法会将中的任何格式错误的个子序列替换 source 为中的 U + FFFD destination ,并继续处理缓冲区的其余部分。If 'replaceInvalidSequences' is true, the method replaces any ill-formed subsequences in source with U+FFFD in destination and continues processing the remainder of the buffer. 否则, OperationStatus.InvalidData 如果遇到格式错误的序列,则该方法将返回。Otherwise, the method returns OperationStatus.InvalidData if it encounters any ill-formed sequences.
如果该方法返回错误代码,输出参数将指示已成功转码的数据量,并且可以从这些值推导出格式错误的子序列的位置。If the method returns an error code, the out parameters indicate how much of the data was successfully transcoded, and the location of the ill-formed subsequence can be deduced from these values.
如果 "replaceInvalidSequences" 为 true ,则该方法从不返回 OperationStatus.InvalidData 。If 'replaceInvalidSequences' is true, the method never returns OperationStatus.InvalidData. 如果 "isFinalBlock" 为 true ,则该方法从不返回 OperationStatus.NeedMoreData 。If 'isFinalBlock' is true, the method never returns OperationStatus.NeedMoreData.