In package LazUtils, unit LazUnicode, function UnicodeToWinCP()
You did see that
UnicodeToWinCP takes a
String as argument aka it's a UTF-8 string?
Hi!
Is there a function that converts a UnicodeString directly into an AnsiString with a desired CodePage? (without making a detour via UTF-8)
For backwards compatibility, I need to convert the content of a UnicodeString into the Windows system codepage (Windows.GetACP).
For speed reasons I don't want to convert it to UTF8 first and then do another conversion with SetCodepage().
I use Laz v2.0.8.
Thanks!
If you're creating a command line application without using Lazarus units you can simply cast your
UnicodeString into an
AnsiString (which will be of codepage
CP_ACP). If you use Lazarus units however things get more complicated, because then
DefaultSystemCodePage (which is what
CP_ACP evaluates to) will be set to
CP_UTF8, which does not help in this case...
You
could try to use
TEncoding.Convert in that case... (I did not test this however)