FString To Int
int32 NewInt = FCString::Atoi(*TheString);
FString To Float
float NewFloat = FCString::Atoi(*TheString);
FString To int
int MyInt = FCString::Atoi(*MyFString);
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<nDataLen;i++)
{
uint8 dst = (uint8)TCHAR_TO_UTF8(pSendData);//
tr_int8.Add(*dst);
pSendData++;
}
return tr_int8;
}
FString To FName
FName NewName = FName(*TheString);
FString To FText
FText NewText = FText::FromString(TheString);
FString To std::string
std::string MyStdString(TCHAR_TO_UTF8(*TheString));
FString To MD5(FString)
FMD5::HashAnsiString(TEXT(“someStuff”));
FString To streamIO
FString InValue; //FString有/0要+1 只支持英文
InValue.GetCharArray().GetData()
//Write(InValue.GetCharArray().GetData(), InValue.Len() + 1);
*this << InValue.GetCharArray();
return *this;
streamIO To FString
*this >> InValue.GetCharArray();
return *this;
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<const char*>(BinaryArray.GetData()), BinaryArray.Num());
//(FString can take in the c_str() of a std::string)
return FString(cstr.c_str());
}
//FString::Printf(TEXT("%s"), UTF8_TO_TCHAR(reinterpret_cast<const char*>(Request.Body.GetData())));
std:string To FString
FString NewString(TestString.c_str());
//(示例std::string TestString = "TestString";)
double To FString
FString::Printf(Text(“%0.14f”),xxx);
char To FString
UTF8_TO_TCHAR(char)
TCHAR To FString
TCHAR* dd =TEXT("aa");
FString cc = dd;
TCHAR To std:string
for (TArray<const TCHAR*>& ite : content)
{
const std::string cstr(reinterpret_cast<const char*>(ite.GetData()),ite.Num());
}
FName To FText
NewText = FText::FromName(TestName);
Enum To FString
template
FString XXXHandle::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);
FString UKismetNodeHelperLibrary::GetEnumeratorUserFriendlyName(const UEnum* Enum, uint8 EnumeratorValue)
{
if (nullptr != Enum)
{
return Enum->GetDisplayNameTextByValue(EnumeratorValue).ToString();
}
return FName().ToString();
}
EMyEnum::Type MyVariable;
static const UEnum* Enum = StaticEnum<EMyEnum::Type>();
Enum->GetNameStringByValue(MyVariable);
Enum To int32
int32 ChunkStatus = static_castEnumAA;
FString To Enum
template
TEnum xxxHandle::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"))
);
std:string To char*
char* name = _strdup(othername.c_str());
(char*)clearText.c_str()
std:string To const char*
const char* name = othername.c_str();
char* To FString
char+=FString;
ANSICHAR To TCHAR
ANSICHAR IndexA = I+65;
TCHAR ANSIChar = FString(&IndexA).GetCharArray()[0];
return FString(&ANSIChar);
char To FString
FString.AppendChar(char);
//or (FString)UTF8_TO_TCHAR(char);
UnixTime To DateTime
int64 UMyBlueprintFunctionLibrary::NowUnix()
{
return FDateTime::UtcNow().ToUnixTimestamp();
}
DateTime To UnixTime
FDateTime DateTime = FDateTime::FromUnixTimestamp(UnixTime);
int64 To FString
FString::Printf(TEXT(“%lld”),time);//time int64
JsonObject To Fstring
TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&JsonStr);
FJsonSerializer::Serialize(JsonObject.ToSharedRef(), Writer);
FString To JsonObject
TSharedPtr JsonObject = MakeShareable(new FJsonObject);
TSharedRef< TJsonReader<> > Reader = TJsonReaderFactory<>::Create(JsonStr);
FJsonSerializer::Deserialize(Reader, JsonObject );
编辑器显示中文
TCHAR_TO_UTF8();
UTF8_TO_TCHAR();
FString chinese = FString::Printf(TEXT("%s"),*str);
NewColumn.StringValue = FString::Printf(TEXT("%s"), UTF8_TO_TCHAR(sqlChars));
FString::Printf(TEXT("%s"), UTF8_TO_TCHAR(reinterpret_cast<const char*>(Request.Body.GetData())));
FString to Base64
TArray<uint8> outArray;
FBase64::Decode(baseString, outArray);
std::string to const unsigned char*
const unsigned char *ptr = (const unsigned char *)cstr.c_str();
CString to string
void CString2char(CString cstr,char CharString[])
{
LPCWCHAR origString = cstr;
size_t origsize = wcslen(origString) + 1;
size_t convertedChars = 0;
wcstombs_s(&convertedChars, CharString, origsize, origString, _TRUNCATE);
}
char to uint8
char Data[1024] = "Hello,I'm client";
(uint8*)Data ;//隐式转换
Hex to Byte
uint8 UXXXHelper::HexToByte(FString Hex)
{
uint8 OutDec;
Hex.StartsWith("#") ? Hex = Hex.Mid(1,Hex.Len()-1) : Hex;
HexToBytes(Hex.ToUpper(), &OutDec);
return OutDec;
}
Byte to Hex
static FORCEINLINE FString ByteToHex(uint8 Byte) { return FString::Printf(TEXT(“%02X”), Byte); }
Hex to Color
static FORCEINLINE FColor HexToColor(FString Hex) { return FColor::FromHex(Hex); }文章来源:https://www.toymoban.com/news/detail-757471.html
Hex to LinearColor
static FORCEINLINE FLinearColor HexToLinearColor(FString Hex) { return FLinearColor(FColor::FromHex(Hex)); }文章来源地址https://www.toymoban.com/news/detail-757471.html
LinearColor to Hex
static FORCEINLINE FString LinearColorToHex(const FLinearColor Color, const bool IsSRGB) { return Color.ToFColor(IsSRGB).ToHex(); }
uint8 to FColor
void FxxxCommonUtils::Uint8ToFColor(const TArray<uint8>& OrginArray, TArray<FColor>& OutArray)
{
for (int32 i = 0;i < OrginArray.Num();i += 4)
{
FColor c;
c.R = OrginArray[i + 0];
c.G = OrginArray[i + 1];
c.B = OrginArray[i + 2];
c.A = OrginArray[i + 3];
OutArray.Add(c);
}
}
Texure to int8
uint8* MipData = static_cast<uint8*>(SrcTex->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
int32 w = SrcTex->GetSurfaceWidth();
int32 h = SrcTex->GetSurfaceHeight();
uint8* SrcPtr = nullptr;
for (int32 y = 0;y < h;++y)
{
SrcPtr = &MipData[y * w * sizeof(FColor)];
for (int32 x = 0;x < w;++x)
{
uint8 R = *SrcPtr++;
uint8 G = *SrcPtr++;
uint8 B = *SrcPtr++;
uint8 A = *SrcPtr++;
Outs.Add(B);
Outs.Add(G);
Outs.Add(R);
Outs.Add(A);
}
}
SrcTex->PlatformData->Mips[0].BulkData.Unlock();
Unicode to UTF8
FString UMyBlueprintFunctionLibrary::UnicodeToUTF8(const FString content)
{
std::string str(TCHAR_TO_UTF8(*content));
std::string u8str;
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
for (size_t i = 0; i < str.length(); ) {
char32_t uhan = strtol(str.substr(i,4).c_str(), nullptr, 16);
u8str += converter.to_bytes(uhan);
i += 4;
}
return UTF8_TO_TCHAR(u8str.c_str());
}
UTF8 to Unicode
FString UMyBlueprintFunctionLibrary::UTF8ToUnicode(const FString content)
{
std::string str(TCHAR_TO_UTF8(*content));
std::string unicodeStr;
size_t length = strlen(str.c_str())+1;
//int32 length = content.Len();
// char * setlocale ( int category, const char * locale );
// 本函数用来配置地域的信息,设置当前程序使用的本地化信息.参数 locale 若是空字符串 "",则会使用系统环境变量的 locale
// 说明string中的字符编码是本机默认字符集,即GB字符集
setlocale(LC_ALL,"");
//wchar_t wstr[length] ;
wchar_t *wstr = new wchar_t[length];
mbstowcs(wstr, str.c_str(), length);
char charUnicode[5];
for (size_t i = 0; i < wcslen(wstr); i++) {
memset(charUnicode, '\0', 5);
sprintf(charUnicode, "%04x", wstr[i]);
unicodeStr.append(charUnicode);
}
return unicodeStr.c_str();
}
到了这里,关于UE4类型转换大全的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!