ANSITOWIDE$ function returns a wide-character (Unicode) string converted from a character string. ANSITOWIDE, UCODE$, and A2W$ are aliases for ANSITOWIDE$
Syntax:RetPWSTR = ANSITOWIDE$(Multibyte AS STRING _ [, CodePage AS INTEGER, dwFlags AS INTEGER, NULLTerm AS BOOL]) Return Value:
Parameters:
|
DIM AS INTEGER RetVal DIM AS STRING Aphorism DIM AS STRING Caption Caption = " ἹΠΠΟΚΡΑΤΟΥΣ " $FILL Aphorism " Ὁ βίος βραχύς," & CRLF$ " ἡ δὲ τέχνη μακρή," & CRLF$ " ὁ δὲ καιρὸς ὀξύς," & CRLF$ " ἡ δὲ πεῖρα σφαλερή," & CRLF$ " ἡ δὲ κρίσις χαλεπή." & CRLF$ $FILL DIM AS PWSTR Caption_UTF16 Caption_UTF16 = A2W$(Caption, 65001) DIM AS PWSTR Aphorism_UTF16 Aphorism_UTF16 = A2W$(Aphorism, 65001) RetVal = MessageBoxW(GetActiveWindow(), Aphorism_UTF16, Caption_UTF16, MB_SYSTEMMODAL)
WIDETOANSI$ function returns a character string converted from a wide-character (Unicode) string. WIDETOANSI, ACODE$, and W2A$ are aliases for WIDETOANSI$
Syntax:RetStr = WIDETOANSI$(UnicodeStr AS LPWSTR _ [, CodePage AS INTEGER, dwFlags AS INTEGER]) Return Value:
Parameters:
|
👉 The example below shows that data converted from UTF-8 and UTF-16 to non-Unicode encodings is subject to data loss, because a code page might not be able to represent every character used in the specific Unicode data. The Unicode glyphs, unrepresentable when converted to the Greek code page 1253, are substituted with "?".
DIM AS UINT OEMCodePage OEMCodePage = GetOEMCP() PRINT "Current OEM Code Page (OEMCP): ", STR$(OEMCodePage) DIM AS UINT WindowsCodePage WindowsCodePage = GetACP() PRINT "Current Windows Code Page (ACP): ", STR$(WindowsCodePage) ? DIM AS UINT OriginalConsoleOutputCodePage OriginalConsoleOutputCodePage = GetConsoleOutputCP() PRINT "Current Console Code Page: ", STR$(OriginalConsoleOutputCodePage) DIM AS STRING ελληνικά $FILL ελληνικά " Ὁ βίος βραχύς," & CRLF$ " ἡ δὲ τέχνη μακρή," & CRLF$ " ὁ δὲ καιρὸς ὀξύς," & CRLF$ " ἡ δὲ πεῖρα σφαλερή," & CRLF$ " ἡ δὲ κρίσις χαλεπή." & CRLF$ $FILL PRINT ελληνικά ? SetConsoleOutputCP(65001) DIM AS UINT CurrentCodePage CurrentCodePage = GetConsoleOutputCP() PRINT "Current Console Code Page: ", STR$(CurrentCodePage) PRINT ελληνικά ? DIM AS PWSTR ελληνικά_UTF16 ελληνικά_UTF16 = A2W$(ελληνικά, 65001) DIM AS STRING ελληνικά_1253 ελληνικά_1253 = W2A$(ελληνικά_UTF16, 1253) SetConsoleOutputCP(1253) CurrentCodePage = GetConsoleOutputCP() PRINT "Current Console Code Page: ", STR$(CurrentCodePage) PRINT ελληνικά_1253 PAUSE SetConsoleOutputCP(OriginalConsoleOutputCodePage)
👉 Data converted from UTF-8 and UTF-16 to non-Unicode encodings is subject to data loss. The Unicode glyphs, unrepresentable when converted to the Greek code page 1253, are substituted with "?".