`
aigo
  • 浏览: 2705369 次
  • 性别: 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!

 

分享到:
评论

相关推荐

    UE基础面试,比较难回答的问题\字符串\代理\容器等

    UE中主要使用三种字符串类型:`FString`、`FText`、`FName`。 - **FString**:标准字符串类型,适合文本存储和处理。 - **FText**:国际化文本类型,支持多语言和格式化。 - **FName**:命名空间内的唯一标识符,...

    第四届ITAT C语言程序设计预赛试题(5)

    根据提供的文件信息,我们可以整理出一系列与C语言相关的知识点,具体包括但不限于数据类型、运算符、位操作、文件处理、循环结构以及字符串处理等。下面将对这些知识点进行详细的阐述。 ### 1. 联合体(Union)与...

    FATFS常用函数详解

    - `TF_EXEC_TYPE_PRINTF`: 向文件打印格式化字符串。 - `TF_EXEC_TYPE_GETS`: 从文件读取字符串。 这些定义为后续函数的使用提供了基础框架。 #### 2. f_read8 `f_read8` 函数用于从文件中读取单个字节的数据。该...

    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 ...

    Object_pascal中文介绍

    property Name: string read FName; procedure Greet; end; procedure TPerson.Greet; begin WriteLn('Hello, ', FName); end; ``` ### 3. 继承 Object Pascal 支持单一继承,一个类可以从另一个类派生,继承...

    TLE及程序由TLE到COE

    % fname is a filename string for a file containing % a two-line element set (TLE) % oe is a 1x6 matrix containing the orbital elements % [a e i O oM M] % yr is the two-digit year % M is the mean ...

    常用Linux命令手册

    - `find / -name "*fname*"`: 从根目录开始查找文件名中包含字符串`fname`的文件。 - `locate missingfilename`: 使用`locate`命令查找名为`missingfilename`的文件,这需要事先运行`updatedb`命令来更新文件索引...

    struts1下图片上传下载

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

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

    #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* ...

    数据库中处理SQL语句两大妙招

    例如,如果查询条件是 `Paolo'f`,则需要将其转换为 `Paolo''f`。VB中提供了一个名为`ProcessStr`的函数来完成这个任务。函数遍历字符串,每当遇到单引号时,就在其前添加一个单引号。这样,数据库引擎将正确解析...

    flex学习笔记,技巧学习

    这里假设`bookdata`已经定义为某种类型的数据结构(例如数据集或对象),通过`ArrayUtil.toArray()`将其转换为数组形式,以便于后续处理。 #### 使用ArrayCollection管理数据 - **`ArrayCollection`**: Flex中非常...

    2013计算机二级考试题库11-20.pdf

    - 字符串函数的使用,如`strcmp`,`strlen`,`strcpy`等,这些函数在`#include &lt;string.h&gt;`后使用。 - 字符的条件判断和操作,如`if(*p &gt;= 'a' && *p )`。 7. 数学函数和数学运算 - 数学库函数的使用,如`sqrt`...

    struts 文件上传下载 程序

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

    从oracle数据库中存取图片

    4. **转换为图片并显示**:将二进制流转换为字节数组,并使用`ImageIcon`类将其转换为可以在Swing组件中显示的图片格式。 示例代码如下: ```java try { Class.forName("oracle.jdbc.driver.OracleDriver"); ...

    Listview 浏览照片及相关信息

    Canvas.Brush.Color := $F9f9f9; Canvas.FillRect(ItemRect); PhotoWidth := 90; PhotoHeight := 85; Margin := 5; SetRect(R, ItemRect.Left + Margin, ItemRect.Top + Margin, ItemRect.Left + Margin + ...

    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;...

    操作系统课程设计 天津科技大学 二级文件系统设计 答案 完整代码 Liunx

    int flength; // 文件长度 int fmode; // 文件模式:0 - 只读;1 - 只写;2 - 读写 char fname[MAXNAME]; // 文件名 } OSFILE; // 用户文件目录结构体 typedef struct { char ufdname[MAXNAME]; // 用户文件...

Global site tag (gtag.js) - Google Analytics