jquave 发表于 2022-5-7 19:36

UE 常用转换

C++输出字符串

FString filePathUE_LOG(LogTemp, Log, TEXT("%s"), *filePath); UE_LOG(LogTemp, Error, TEXT("Hello,World!"));输出字符串到屏幕上

FString filePath;GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("DLL_Init"))); GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("%s"), *filePath));字符串转换

Converting FString to FNames

FString TheString = "UE4_C++_IS_Awesome";FName ConvertedFString = FName(*TheString);Converting std::string to FString

#include <string>//....std::string TestString = "Happy"; FString HappyString(TestString.c_str());Converting FString to std::string

#include <string>//....FString UE4Str = "Flowers";std::string MyStdString(TCHAR_TO_UTF8(*UE4Str));
数值转std::to_string
std::string to_string( long value );std::string to_string( long long value );std::string to_string( unsigned value );std::string to_string( unsigned long value );std::string to_string( unsigned long long value );std::string to_string( float value );std::string to_string( double value );std::string to_string( long double value );Converting FString to Integer

FString TheString = "123.021";int32 MyShinyNewInt = FCString::Atoi(*TheString);Converting FString to Float

FString TheString = "123.021";int32 MyShinyNewInt = FCString::Atof(*TheString);Converting Float/Integer to FString

FString NewString = FString::FromInt(YourInt);FString VeryCleanString = FString::SanitizeFloat(YourFloat);UE4 Source Header References

CString.hUnrealString.hNameTypes.hStringConv.h (TCHAR_TO_ANSI etc)
CString.h可以查到更多,如
atoi64 (string to int64)Atod    (string to double precision float)
更多关于FString的操作可以到UnrealString.h找到.
Converting FArrayReaderPtr to FString

uint8 data;FMemory::Memzero(data, 512);   FMemory::Memcpy(data, ArrayReaderPtr->GetData(), ArrayReaderPtr->Num());FString str = ((const char*)data); Converting Array to FString

TArray<uint8> content;...const std::string cstr(reinterpret_cast<const char*>(content.GetData()), content.Num());FString frameAsFString = cstr.c_str();UE_LOG(VRSLog, Warning, TEXT("%s"), *frameAsFString); Converting FString to Array

FString JsonStr;TArray<uint8> content;   content.SetNum(JsonStr.Len());memcpy(content.GetData(), TCHAR_TO_ANSI(*JsonStr), JsonStr.Len()); FString StrData;const TCHAR* StrPtr = *StrData;FTCHARToUTF8 UTF8String(StrPtr);int32 CTXSize = UTF8String.Length();   TArray<uint8> URLData;URLData.SetNum(CTXSize);memcpy(URLData.GetData(), UTF8String.Get(), CTXSize);Converting FString to char *

///1FString strstring t = TCHAR_TO_UTF8(*str);char * returnvalue = (char *)malloc(sizeof(char) * (t.length() + 1));strncpy_s(returnvalue, t.length() , t.c_str(), t.length());   ///2int ARPG_Database::BP_GetColumnIndex(int resultSet, FString columnName){    return GetColumnIndex(resultSet, TCHAR_TO_ANSI(*columnName));} int ARPG_Database::GetColumnIndex(int iResult, const char* columnName){}Converting FString to const char *

Converting FString to const char *Converting FString to TCHAR *

int ARPG_Database::BP_GetColumnIndex(int resultSet, FString columnName) {   return GetColumnIndex(resultSet, *columnName); }int ARPG_Database::GetColumnIndex(int iResult, const TCHAR* columnName) { }Converting FString to FText

FString Str = TEXT("str");FText Text = FText::FromString(Str);Converting FText to FString

FString Name = NameDesc->GetText().ToString(); 参考


Logs, Printing Messages To Yourself During Runtime

UEngine::AddOnScreenDebugMessage

String Conversions: FString to FName, FString to Int32, Float to FString

字符编码

String Casting Fun in Unreal Engine 4 UPDATED

虚幻4学习—UE4中的字符串转换

转载:(167条消息) 【UE4学习】C++输出字符串及FString字符串转换_德智的博客-CSDN博客_fstring转string
页: [1]
查看完整版本: UE 常用转换