String Conversions:

FString To FName

FString To Int32

Float To FString

FArrayReaderPtr To FString

TArray<uint8> To FString

FString To char *  ---  (  TCHAR_TO_ANSI()  )

FString To TCHAR *

FString To Array<uint8>

FString To FText (新增)

FText 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

FArrayReaderPtr to FString

uint8 data[];
FMemory::Memzero(data, ); FMemory::Memcpy(data, ArrayReaderPtr->GetData(), ArrayReaderPtr->Num());
FString str = ((const char*)data);

Array<uint8> 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);

FString to char *  TCHAR_TO_ANSI()

int BP_GetColumnIndex(int resultSet, FString columnName)
{
return GetColumnIndex(resultSet, TCHAR_TO_ANSI(*columnName));
} int GetColumnIndex(int iResult, const char* columnName)
{
}

FString to TCHAR *

int BP_GetColumnIndex(int resultSet, FString columnName)
{
return GetColumnIndex(resultSet, *columnName);
} int GetColumnIndex(int iResult, const TCHAR* columnName)
{
}

FString To Array<uint8>

// 简洁用法
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);

FString To FText

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

FText To FString

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

[UE4] 虚幻4学习---UE4中的字符串转换的更多相关文章

  1. Objective - C 中NSString (字符串)与C中的字符串转换问题

    NSString是一个常用的类,NSString是原生支持unicode C中的字符串 比如char * a = "hello world";  是utf8类型的, char* d ...

  2. VC中的字符串转换宏

              ATL7.0引入了几个新的转换类和宏,现有的宏提供了显着的改善.新的字符串转换类和宏的名称,采取的形式如下: C SourceType [C]DestinationType[EX] ...

  3. js中把字符串转换成number格式方法

    方法主要有三种 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后者把值转换成浮点数.只有 ...

  4. 深入学习Java中的字符串,代码点和代码单元

    在Java字符串处理时,在使用length和charAt方法时,应该格外小心,因为length返回的是UTF-16编码表示下的代码单元数量,而非我们所认为的字符的个数,charAt方法返回的是指定位置 ...

  5. URL地址中的字符串转换

    url出现了有+,空格,/,?,%,#,&,=等特殊符号的时候,可能在服务器端无法获得正确的参数值,怎么解决?解决办法将这些字符转化成服务器可以识别的字符,对应关系如下:URL字符转义 用其它 ...

  6. asp.net 中json字符串转换

    List<ATTVal> Replys = JsonParser.FromJson<List<ATTVal>>(attrValueStr);

  7. [转] String to Date conversion in hive - 在 Hive 中各种字符串转换成日期格式

    [From] http://bigdataprogrammers.com/string-date-conversion-hive/ Please refer below table to conver ...

  8. OC中的字符串常用方法

    OC中的字符串常用方法 OC中对字符串进行操作使用了Foundation框架中的NSString类(不可变).NSMutableString类(可变). NSString 1.创建字符串 [objc] ...

  9. [C++] zlatlcv: ATL字符串转换辅助库。能很方便的将UTF-8字符串转为TCHAR等字符串

    作者:zyl910 如今,UTF-8字符串的使用频率越来越多了.但是在VC中,不能直接处理UTF-8字符串,得专门去写UTF-8与窄字符串.宽字符串.TCHAR字符串相互转换的代码.不仅费时费力,而且 ...

随机推荐

  1. 关于plantera

    在Plantera,您可以建立属于您自己的花园,并且看着新的植物,灌木,树木和动物一起生长. 当您进行游戏,扩张您的花园时,您会吸引圆滚滚的蓝色生物小助手们,它们将帮助您捡果子,收获您的植物 有时候会 ...

  2. Adaboost算法流程及示例

    1. Boosting提升方法(源自统计学习方法) 提升方法是一种常用的统计学习方法,应用十分广泛且有效.在分类问题中,它通过改变训练样本的权重,学习多个分类器,并将这些分类器进行线性组合,提高分类的 ...

  3. word-如何将文字设置为插入超链接

    前言 使用word有时候想要将文字部分设置为插入超链接,本文对此进行介绍. 操作步骤 1. 输入需要插入链接的文字部分: 2. 选中文字部分单击右键,点击超链接进行插入: 具体操作如下图所示: 参考 ...

  4. pip模块的使用

    安装pip: sudo apt-get install python-pip           (python2的安装) sudo apt-get install python3-pip      ...

  5. 20分钟打造你的Bootstrap站点

    来源:http://www.w3cplus.com/css/twitter-bootstrap-tutorial.html 特别声明:此篇文章由白牙根据Leon Revill的英文文章原名<Tw ...

  6. 一定要记住这20种PS技术,让你的照片美的不行! - imsoft.cnblogs

    照片名称:调出照片柔和的蓝黄色-简单方法, 1.打开原图素材,按Ctrl + J把背景图层复制一层,点通道面板,选择蓝色通道,图像 > 应用图像,图层为背景,混合为正片叠底,不透明度50%,反相 ...

  7. UVA 10305:Ordering Tasks(拓扑排序)

    #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm& ...

  8. UT源码_105032014033

    需求描述: 设计佣金问题的程序 commission方法是用来计算销售佣金的需求,手机配件的销售商,手机配件有耳机(headphone).手机壳(Mobile phone shell).手机贴膜(Ce ...

  9. JS校验 if (! temp_var) {} //拦截 ''和 undefined

    if (! aaa) {}  //拦截   ' '  和  undefined  和  0 不拦截null

  10. Eclipse使用前准备(转)

    Eclipse的发布流程 M1  08/19/2009      M2     09/30/2009     M3     11/11/2009     M4     12/16/2009     M ...