ANSI to UTF8

hi,i have a problem,how can i change char array from ANSI to UTF8
in UE4 there is no such macro,
ANSI_TO_TCHAR,UTF8_TO_TCHAR not works

you can use standard stuff like std::wstring_convert> to do it

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;

string = converter.to_bytes(wideString);
wideString = converter.from_bytes(string);

If you need C style strings “charArray”

string = converter.to_bytes(wideString).c_str();
wideString = converter.from_bytes(string).c_str();

cool,thank you ,i will try

ANSI can convert to TCHAR by simply putting it in an FString. Internally it has a TCHAR array, and can be accessed as such with *.

ANSICHAR ANSIStr[8];
FString MyNewStr(ANSI_TO_TCHAR(ANSIStr));

Then converted to UTF8 via

ANSICHAR* MyUTF8 = TCHAR_TO_UTF8(*MyNewStr);

NOTE: This pointer must not be kept for long, you need to copy the data out as the memory will be release when the code goes out of scope.

I thought TCHAR was UTF16, not UTF8?

TCHAR is just a define for a 1 or 2 byte character depending on the platform. Ideally that is an opaque issue and with the right functions something that you shouldn’t have to worry about.

I’m not a UTF/Unicode expert, but you should consider UTF8/16 encodings that strings are written two, independent of TCHAR.

If anything UTF8 means to look at the bytes of the “string” in a stride of 1. It doesn’t mean that a character is 1 byte in size.