CLEAR * UTF-8 to Unicode DECLARE INTEGER MultiByteToWideChar IN WIN32API ; INTEGER code_page, ; INTEGER flags, ; STRING mbString, INTEGER mbStringLength, ; STRING wcharString, INTEGER wcharStringLength * Unicode to UTF-8 DECLARE INTEGER WideCharToMultiByte IN WIN32API ; INTEGER code_page, ; INTEGER flags, ; STRING wcharString, INTEGER wcharStringLength, ; STRING mbString, INTEGER mbStringLength, ; STRING defaultChar, ; INTEGER@ default_char_was_used in = "test" out = space(32) in = MultiByteToWideChar(65001, 0, in, LEN(in), @out, LEN(out) / 2) ? ALLTRIM(out) * Reverse it in = ALLTRIM(ALLTRIM(out, 1, CHR(0))) out = space(32) llDefaultCharWasUsed = .f. WideCharToMultiByte(65001, 0, in, LEN(in) / 2, @out, LEN(out), " ", @llDefaultCharWasUsed) ? ALLTRIM(out)The UTF-8 file format has a leading BOM marker you'll need to write with FWRITE() first. This indicates to the file loader what format the file is in:
FWRITE(fh, CHR(0xEF) + CHR(0xBB) + CHR(0xB)) * Write the rest of your content after this. Most apps will interpret straight-ansi as utf-8 without issue in my experience.