FString from a single TCHAR

Hi,

I’ve been trying to find a way to construct a FString from a single TCHAR so far this is what I’ve come up with and I’d like to know if you guys have any better methods.

First method:

TCHAR c = 'A';
FString str = FString(1, &c);

UE_LOG(LogTemp, Warning, TEXT("%s"), *str);

Second method using TArray

TCHAR c = 'A';
TArray<TCHAR> arr = { c, '\0'}; //null terminator needed.
TCHAR* ArrPtr = &arr[0];
FString str = ArrPtr;

UE_LOG(LogTemp, Warning, TEXT("%s"), *str);

Edit:
Second method I can also use instead of TArray I guess.
TCHAR arr[] = {c, '\0'};

Third method:

FString str;
str.AppendChar(c);

Thank you.

Couple more ways this this thread:

Convert std::string to FString - Programming & Scripting / C++ - Unreal Engine Forums

Although I’d suggest using nothing other than FStrings if it can be avoided.

Thanks for replying. That thread has some good info but I couldn’t see anything related to one single TCHAR to FString.
I also agree I’d rather stay within the scope of unreal engine types.

Thanks again.

if you’re specifically intending to print this TCHAR variable to the log, you can format it like this:

TCHAR c = 'A';
UE_LOG(LogTemp, Warning, TEXT("%c"), c);