笔记:UE4各个类型之间的转换

FString TheString = "String"

FString To Int

int32 NewInt = FCString::Atoi(*TheString);

FString To Float

float NewFloat = FCString::Atoi(*TheString);

FString To bool

bool bNewbool = TestString.ToBool();

FString To char*

TCHAR_TO_UTF8(*content)

FString To Tchar

MyTchar = *MyFString;

FString To uint8

TArray AMyActor::UintConvert()
{
	FString szMsg = "gest";
	TArray tr_int8;
	TCHAR* pSendData = szMsg.GetCharArray().GetData();
	int32 nDataLen = FCString::Strlen(pSendData);
	for (int i=0;i

FString To FName

FName NewName = FName(*TheString);

FString To FText

FText NewText = FText::FromString(TheString);

FString To std::string (需要包含#include 或者#include 和using namespace std;)

std::string MyStdString(TCHAR_TO_UTF8(*TheString));

FString To MD5(FString)

FMD5::HashAnsiString(TEXT("someStuff"));

 

Int To FString

FString NewString = FString::FromInt(MyNewInt);

 Float To FString

FString NewString = FString::SanitizeFloat(MyNewFloat);

 FText To FString

FString NewString  = TestText.ToString();

FName To FString

FString NewString = TestName.ToString(); 

uint8 To FString

FString AMyActor::UintConvert2()
{
	const TArray& BinaryArray = {103, 116};
	//(Create a string from a byte array!)
	const std::string cstr(reinterpret_cast(BinaryArray.GetData()), BinaryArray.Num());
	//(FString can take in the c_str() of a std::string)
	return FString(cstr.c_str());
}

std:string To FString

FString NewString(TestString.c_str());
//(示例std::string TestString = "TestString";)

char to FString

UTF8_TO_TCHAR(char)

TCHAR to FString

TCHAR* dd =TEXT("aa");
FString cc = dd;

TCHAR to std:string

for (TArray& ite : content)
{
	const std::string cstr(reinterpret_cast(ite.GetData()),ite.Num());
}

FName To FText

NewText = FText::FromName(TestName);

枚举转字符串

template
FString SlAiDataHandle::GetEnumValueAsString(const FString& Name, TEnum Value)
{
	const UEnum* EnumPtr = FindObject(ANY_PACKAGE, *Name, true);
	if (!EnumPtr) {
		return FString("InValid");
	}
	return EnumPtr->GetNameStringByIndex((int32)Value);
}

ESecondCategory SecCategory;
FString CategoryName = GetEnumValueAsString(FString("ESecondCategory"), SecCategory);

字符串转枚举

template
TEnum SlAiDataHandle::GetEnumValueFromString(const FString& Name, FString Value)
{
	const UEnum* EnumPtr = FindObject(ANY_PACKAGE, *Name, true);
	if (!EnumPtr) {
		return TEnum(0);
	}
	return (TEnum)EnumPtr->GetIndexByName(FName(*FString(Value)));
}

FString CategoryName;
ESecondCategory SecCategory = GetEnumValueFromString(FString("ESecondCategory"), *CategoryName);

FString to FText的NSLOCTEXT

	FText Message = FText::Format(
		NSLOCTEXT("UnrealClient", "{0}", "{1}"),
		FText::FromString(tips),
		FText::FromString(TEXT("aa"))
	);

char* to FString  

char+=FString;

char to FString

FString.AppendChar(char);

 

你可能感兴趣的:(UE4)