How to convert FString to TArray< uint8 >?

Hi

Is there any existing function to convert FString to TArray< uint8 >? FString is UTF8.

Thanks in advance.

Hey! I found this in the Engine code where it does what I think you are asking about.

int32 Utf8Length = FTCHARToUTF8_Convert::ConvertedLength(*ContentString, ContentString.Len());
TArray<uint8> Buffer;
Buffer.SetNumUninitialized(Utf8Length);
FTCHARToUTF8_Convert::Convert((UTF8CHAR*)Buffer.GetData(), Buffer.Num(), *ContentString, ContentString.Len());

The Buffer variable is the resulting TArray. This code can be found at /Engine/Source/Runtime/Online/HTTP/Private/Curl/CurlHttp.cpp:334 and it’s specifically used for setting an HTTP request body to the value of an FString.

1 Like