zwcloud
zwcloud

Reputation: 4889

How to convert char* to TCHAR in Unreal Engine 4?

For example,

const char* bytes = "somemultibytecharacter一些宽字符";
size_t n = strlen(bytes);

How to convert bytes to FString or TCHAR* in Unreal Engine C++ code?

I know I can convert with std::mbstowcs or MultiByteToWideChar, but I'm trying to find a UE4 alternative.

Upvotes: 5

Views: 9781

Answers (1)

zwcloud
zwcloud

Reputation: 4889

Just use FString(int32 InCount, const CharType* InSrc).

Usage:

const char* bytes = "somemultibytecharacter一些宽字符";
size_t n = strlen(bytes);
const FString& Str = FString(n, bytes);
const TCHAR* Text = *Str;

Note, in my copy of Unreal Engine 4, TCHAR is wchar_t:

typedef wchar_t  WIDECHAR;
typedef WIDECHAR TCHAR

Upvotes: 3

Related Questions