`
aigo
  • 浏览: 2535814 次
  • 性别: Icon_minigender_1
  • 来自: 宜昌
社区版块
存档分类
最新评论

[UE4]字符串类型转换:FString to FName, FString to Int32, Float to FString

UE4 
阅读更多

官方文档:

https://wiki.unrealengine.com/String_Conversions:_FString_to_FName,_FString_to_Int32,_Float_to_FString

 

Overview

  1. FString to FName
  2. std::string to FString
  3. FString and FCString Overview
  4. FString to Integer
  5. FString to Float
  6. Float/Integer to FString
  7. UE4 C++ Source Header References

All the header files I refer to in this tutorial are found in

your UE4 install directory  / Engine / Source

you will probably want to do a search for them from this point :)

Converting FString to FNames

Say we have

FString TheString = "UE4_C++_IS_Awesome";

To convert this to an FName you do:

FName ConvertedFString = FName(*TheString);

std::string to FString

#include <string>
 
//....
 
some function
{
  std::string TestString = "Happy"; 
  FString HappyString(TestString.c_str());
}

FString to std::string

#include <string>
 
//....
FString UE4Str = "Flowers";
std::string MyStdString(TCHAR_TO_UTF8(*UE4Str));

FCString Overview

Converting FString to Numbers

The * operator on FStrings returns their TCHAR* data which is what FCString functions use.

If you cant find the function you want in FStrings (UnrealString.h) then you should check out the FCString functions (CString.h)

I show how to convert from FString to FCString below:

Say we have

FString TheString = "123.021";

FString to Integer

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

FString to Float

float MyShinyNewFloat = FCString::Atof(*TheString);


Note that Atoi and Atof are static functions, so you use the syntax FCString::TheFunction to call it :)

 

Float/Integer to FString

FString NewString = FString::FromInt(YourInt);
 
FString VeryCleanString = FString::SanitizeFloat(YourFloat);

Static functions in the UnrealString.h :)

UE4 Source Header References

CString.h
UnrealString.h
NameTypes.h

See CString.h for more details and other functions like

atoi64 (string to int64)
Atod	(string to double precision float)


For a great deal of helpful functions you will also want to look at

UnrealString.h for direct manipulation of FStrings!

 

For more info on FNames check out

 NameTypes.h

Enjoy!

 

分享到:
评论

相关推荐

    From C to C++

    // convert a string to uppercase! #include #define N 200 int main(){ char ms[N]; int i; printf("Input ms: "); gets(ms); for(i=0;ms[i];i++) if(ms[i]&gt;='a'&&ms[i]) ms[i]-='\x20'; puts(ms); ...

    k-mean聚类算法实现

    #include &lt;string.h&gt; #include #include // FUNCTION PROTOTYPES // DEFINES #define SUCCESS 1 #define FAILURE 0 #define TRUE 1 #define FALSE 0 #define MAXVECTDIM 20 #define MAXPATTERN 20 #define ...

    编译原理 词法分析(内有源代码)

    #include&lt;string.h&gt; char ch; #define ID 100; #define I 20; char token[20]; int d=0; //int i=0; bool isanum(char ch); bool isaabc(char ch); void scanner_exam(FILE *f); struct option{ int Class; char* ...

    PB串口通讯源码-API

    FUNCTION ulong CreateFileA(ref string fname, ulong f_access, ulong f_share, ulong f_sec, ulong f_create, ulong f_flag, ulong f_attrib) LIBRARY "kernel32.dll" Function Boolean WriteFile(uLong handle,...

    asp连接数据库代码实例

    response.write \"数据库连接出错,请检查conn.asp中的连接字符串。\" response.end end if function CloseDB Conn.Close set Conn=Nothing End Function %&gt; dim badword badword=\"\'|and|select|update|...

    文件系统代码

    #include #include #include &lt;string&gt; #include using namespace std;... memset(p,4,BlockSize); printf("----------------------------------------------------------------\n\n"); return 1;...

    strust文件上传

    float ok1=(((float)ok)/1024f/1024f); DecimalFormat myformat1 = new DecimalFormat("0.00"); strFee = myformat1.format(ok1)+"M"; System.out.println(strFee+"M"); } else if(ok&gt;1024 && ok*1024) { ...

    小型简单的记事本程序

    String str,strnext,path,fname; //部分变量的声明 JPanel mainpane; JFileChooser choose = new JFileChooser(); //文件对话框 Dialog find,replace; //find为查找对话框,replace对话框 JTextField findtxt,...

    js使用小技巧

    让英文字符串超出表格宽度自动换行 word-wrap: break-word; word-break: break-all; 透明背景 &lt;IFRAME src="1.htm" width=300 height=180 allowtransparency&gt;&lt;/iframe&gt; 获得style内容 obj.style.cssText ...

    fitsio:fitsio是一个纯Go软件包,用于读取和写入`FITS`文件

    func dumpFitsTable ( fname string ) { r , err := os . Open ( fname ) if err != nil { panic ( err ) } defer r . Close () f , err := fits . Open ( r ) if err != nil { panic

    基于lf蚁群聚类算法

    %-- 10-9-1 下午4:54 --% %-- 10-9-1 下午8:09 --% load('E:\苏雪敬个人资料\苏雪敬-开题报告\程序代码\matlab.mat') %-- 10-9-2 上午9:01 --% load('E:\苏雪敬个人资料\苏雪敬-开题报告\程序代码\matlab.mat') %% *...

Global site tag (gtag.js) - Google Analytics