I defined a function in my c++ class
FString UMyBlueprintFunctionLibrary::TestFString()
{
FString m = “你”;
return m;
}
Then I call this function in blueprint,and print the return value.It prints ?? rather than “你”.
This string literal you are passing cannot properly hold Chinese characters.
From https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/StringHandling/index.html
You need to have the literal converted to wide characters otherwise it will try to parse it as a pure ansi string which will be invalid.
EDIT: so with an example:
FString m = TEXT(“你”);
FString UMyBlueprintFunctionLibrary::TestFString(FString m)
{
return m;
}
If I call this function in blueprint and set the parameter of m as “你”,and print the return value.It prints ?? rather than “你”. How can i solve this problem?
maya,
I think the FString data type can only contain ASCII / ASCI characters. You might need to do some encoding to produce the correct character type.
This document might help:
楼主这个问题解决了吗
string UUtilityLib::GBKToUTF8(const string& strGBK)
{
std::string strOutUTF8 = "";
WCHAR* str1;
int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0);
str1 = new WCHAR[n+1];
memset(str1, 0, n * 2 + 2);
MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, str1, n);
n = WideCharToMultiByte(CP_UTF8, 0, str1, -1, NULL, 0, NULL, NULL);
char* str2 = new char[n+1];
memset(str2, 0, n + 1);
WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL);
strOutUTF8 = str2;
delete[]str1;
str1 = NULL;
delete[]str2;
str2 = NULL;
return strOutUTF8;
}
auto name = "mn名字";
auto utf8= UUtilityLib::GBKToUTF8(name);
FString testName = UTF8_TO_TCHAR(utf8.c_str());
Solved my problem! Thank you very much!