System.UnicodeToUtf8
Delphi
function UnicodeToUtf8(Dest: _PAnsiChr; Source: PWideChar; MaxBytes: Integer): Integer;
function UnicodeToUtf8(Dest: _PAnsiChr; MaxDestBytes: Cardinal; Source: PWideChar; SourceChars: Cardinal): Cardinal;
C++
extern DELPHI_PACKAGE int __fastcall UnicodeToUtf8 _DEPRECATED_ATTRIBUTE0 (System::PAnsiChar Dest, WideChar * Source, int MaxBytes)/* overload */;
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.pas System.hpp |
System | System |
Description
Converts a string of Unicode characters into a UTF-8 string.
Call UnicodeToUtf8 to convert a Unicode string to a null-terminated sequence of UTF-8 characters. Use the second syntax. The deprecated syntax is included only for backward compatibility.
Dest receives the resulting null-terminated array of UTF-8 characters.
MaxDestBytes or MaxBytes indicates the number of bytes available in the buffer specified by Dest, including the byte for the null terminator.
Source is an array of Unicode characters.
SourceChars is the number of characters in Source. If SourceChars is not specified, Source must be null-terminated.
UnicodeToUtf8 returns the number of bytes written to Dest.
If the conversion fails, UnicodeToUtf8 returns 0.
Note: One common reason for UnicodeToUtf8 failing is that the destination buffer has not enough memory. In this scenario, UnicodeToUtf8 returns 0 and the destination buffer keeps a partial string.
See Also