虚幻4学习---UE4中的字符串转换(文章来自于UE4官方文档)


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

Enjoy!

------------------------------------------------------------------------------

FArrayReaderPtr to FString

[cpp] view plaincopy
  1. uint8 data[512];
  2. FMemory::Memzero(data, 512);
  3. FMemory::Memcpy(data, ArrayReaderPtr->GetData(), ArrayReaderPtr->Num());
  4. FString str = ((const char*)data);

Array<uint8> to FString

[cpp] view plaincopy
  1. TArray<uint8> content;
  2. ...
  3. const std::string cstr(reinterpret_cast<const char*>(content.GetData()), content.Num());
  4. FString frameAsFString = cstr.c_str();
  5. UE_LOG(VRSLog, Warning, TEXT("%s"), *frameAsFString);

FString to char *  TCHAR_TO_ANSI()

[cpp] view plaincopy
  1. int BP_GetColumnIndex(int resultSet, FString columnName)
  2. {
  3. return GetColumnIndex(resultSet, TCHAR_TO_ANSI(*columnName));
  4. }
  5. int GetColumnIndex(int iResult, const char* columnName)
  6. {
  7. }

FString to TCHAR *

[cpp] view plaincopy
  1. int BP_GetColumnIndex(int resultSet, FString columnName)
  2. {
  3. return GetColumnIndex(resultSet, *columnName);
  4. }
  5. int GetColumnIndex(int iResult, const TCHAR* columnName)
  6. {
  7. }

FString To Array<uint8>

[cpp] view plaincopy
  1. FString StrData;
  2. const TCHAR* StrPtr = *StrData;
  3. FTCHARToUTF8 UTF8String(StrPtr);
  4. int32 CTXSize = UTF8String.Length();
  5. TArray<uint8> URLData;
  6. URLData.SetNum(CTXSize);
  7. memcpy(URLData.GetData(), UTF8String.Get(), CTXSize);

FString To FText

[cpp] view plaincopy
  1. FString Str = TEXT("str");
  2. FText Text = FText::FromString(Str);

FText To FString

[cpp] view plaincopy
  1. FString Name = NameDesc->GetText().ToString();

UE4中的字符串转换相关推荐

  1. mysql转换年月日_mysql中把字符串转换成日期类型:

    mysql中把字符串转换成日期类型: select date_format('2013-03-09','%Y-%m-%d'); select date_format('2013-03-09','%y- ...

  2. python中列表中的字符串转换成数字

    python中列表中的字符串转换成数字 调整实验时,发现某个嵌套列表的字典中需要把列表中的字符串改成数字,不能直接强转,需要以下代码实现 m_dict_G = {}for key in md_dict ...

  3. MFC中的字符串转换

    在VC++中有着一大把字符串类型.从传统的char*到std::string到CString,简直是多如牛毛.期间的转换相信也是绕晕了许多的人,我曾就是其中的一个.还好,MS还没有丧失功德心,msdn ...

  4. 关于datagrid中的字符串转换

    在datagrid中,数据绑定时,怎么把数据库中的字符串按照自己设定的方式进行输出是个比较麻烦的事 这个问题困扰了我很久,也试着使用了很多方法: 1.<pre><%#Containe ...

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

    Input Format Code Output Format ddMMyyyy to_date(from_unixtime(UNIX_TIMESTAMP(dt,'ddMMyyyy'))) yyyy- ...

  6. c语言一个整数各位数字个数_C语言实现把字符串中的数字转换成整数

    ===Tips:点击上方 蓝字 关注并查看历史消息===   本题实现的功能是把字符串中的数字提取转换成整型数字,例如:若输入字符串"ab56cd87",则输出结果:以%d格式输出 ...

  7. c语言求字符串转换成双精度_C语言实现把字符串中的数字转换成整数

    ===Tips:点击上方 蓝字 关注并查看历史消息===   本题实现的功能是把字符串中的数字提取转换成整型数字,例如:若输入字符串"ab56cd87",则输出结果:以%d格式输出 ...

  8. 把数据库中有关枚举项值的数字字符串转换成文字字符串

    原文:把数据库中有关枚举项值的数字字符串转换成文字字符串 标题可能无法表达我的本意.比如,有这样一个枚举: public enum MyChoice { MyFirstChoice = 0, MySe ...

  9. 转换成字符串_汇编语言--将字符串中小写字母转换成大写字母

    将字符串中小写字母转换成大写字母 思路: 将键盘上输入的字符读入 调用DOS 10号功能 利用偏移量的性质(类似指针的移动),逐一将字符转换为大写 在转换完的字符串后面 加上 结束符 '$' 利用DO ...

最新文章

  1. 软件测试第一次作业--石家名 3013218062
  2. 昆山立讯电子工程师_西安立讯科技学院与立讯精密公司签订校企合作战略合作协议...
  3. 》》css3--动画
  4. 计算机的配件知识,组装一台电脑需要哪些配件 DIY装机必看的电脑硬件知识详解 (全文)...
  5. 【卡尔曼滤波】我所理解的卡尔曼滤波
  6. html5 3d场景设计,基于 HTML5 WebGL 的加油站 3D 可视化监控
  7. Grasshopper脚本电池处理全站仪数据,生成建筑、线状地物和地形
  8. 在Linux下驱动D-link DFE-530TX(最终稿)(转)
  9. 酷狗音乐API数据接口--分析
  10. Html Table 合并单元格
  11. 常用DC-DC;AC-DC电源芯片
  12. 服务器网站绕过备案,腾讯云服务器如何利用阿里DCDN绕过备案
  13. 从一到无穷大 #4 Lossy compression
  14. 中国石油大学(华东)校园网络认证脚本
  15. msgbox函数和msgbox语句
  16. Endnote 20(X9)中英文文献引用(毕业论文格式)-自用
  17. 让你意想不到的加密方式——猪圈密码
  18. Asterisk 服务器 Linux平台安装教程
  19. Windows资源管理器占用内存暴涨解决/无响应处理方案
  20. {HTML5学习图谱}随着微信小程序的出现,HTML5将会炙手可热!

热门文章

  1. linux文件基础知识,linux文件系统基础知识
  2. flutter打开第三方应用
  3. Spring Cloud Gateway Predicate.Path过滤分析
  4. 注册表文件(*.reg)的编写及应用
  5. 6个实例详解如何把if-else代码重构成高质量代码
  6. openfeign 负载均衡调用服务
  7. websocket使用
  8. 1010 一元多项式求导 (25分)
  9. 实验10 编写子程序
  10. owncloud nginx php,nginx配置owncloud记录。