当前位置:网站首页>UE4 essays: fstring, fname and ftext
UE4 essays: fstring, fname and ftext
2022-06-27 20:36:00 【Lao Yan is trying】
FString、FName And FText
UE4 There are three classes that handle strings in , To meet different development needs :FString、FName and FText, Between the three difference by :
① FName
Focus on expressing name , Case insensitive , Non modifiable , The resource names in the engine are FName type , Reusing strings through a lightweight system ,FName When creating, a... Will be created according to the content Hash value , And the same content will only be stored once . adopt Hash Value in progress FName Is faster to find and access , In comparison , There is no need to compare the string contents , Direct comparison Hash Value to distinguish between different FName character string .
The other two strings go to FName Transformation ( Special note ,FText Cannot convert directly to FName, Can be converted to FString, Re convert to FName):
FString str = TEXT("Hello world~");
FText txt = LOCTEXT("keyName", "theValue");
FText txtNS = NSLOCTEXT("TextNameSpace", "keyName", "theValue");
// FString turn FName: unreliable , Missing case information
FName name1 = FName(*str);
FString strFromTxt = txt.ToString();
// FText Turn first FString, Re turn FName: unreliable , Missing case information , The loss of localization information may lead to the potential risk of language conversion
FName name2 = FName(*strFromTxt);
② FString
Nearest std::string, The point is String operation , It provides a large number of operation interfaces for strings , Is the only modifiable string type among the three , And that's why ,FString It is more expensive than the other two strings , Lower performance .
The other two strings go to FString Transformation :
FName name = TEXT("I am Frank~");
FText txt = LOCTEXT("keyName", "theValue");
FText txtNS = NSLOCTEXT("TextNameSpace", "keyName", "theValue");
// FName turn FString: reliable
FString str1 = name.ToString();
// FText turn FString: unreliable , The loss of localization information may lead to the potential risk of language conversion
FString str2 = txt.ToString();
③ FText
The point is Display and localization , Display information that can be directly seen by understandable players , Localization is multilingual processing , Non modifiable . Compared with the other two types ,FText Will be more bloated , But it provides excellent localization capabilities .
The other two strings go to FText Transformation :
FString str = TEXT("Hello world~");
FName name = TEXT("I am Frank~");
// FString turn FText: reliable
FText txt1 = FText::FromString(str);
// FName turn FText: reliable
FText txt2 = FText::FromName(name);
It should be noted that , establish FText The control needs to be named and defined Namespace , And open it in the editor Localize control panel features (Localization Dashboard):
I. Declare a text space macro in the current source file , Create... Within the scope of the macro declaration FText Namespace parameters are not required , It is important to note that the declaration must be undeclared at the end of the source file :
// Source.cpp
// Declare text space macros
#define LOCTEXT_NAMESPACE "MyTextNameSpace"
// Macro declaration scope creation FText
FText txt = LOCTEXT("keyName", "theValue");
// The declaration must be cancelled in the appropriate place
#undef LOCTEXT_NAMESPACE
II. Define the namespace in the editor , Can be used directly in code :
// Use the defined namespace
FText txtNS = NSLOCTEXT("TextNameSpace", "keyName", "theValue");
边栏推荐
- Eval function, global, local variables
- Batch insert data using MySQL bulkloader
- NVIDIA three piece environment configuration
- Redis cluster Series II
- Redis cluster
- Mass lucky hash game system development - conflict resolution (code analysis)
- Hash table - Review
- [STL programming] [common competition] [Part 3]
- SQL Server - window function - solve the problem of filtering consecutive n records
- Redis集群
猜你喜欢

Database lock problem

Database index

Database log

Redis data structure

DBeaver恢复和备份数据库的方式

SQL审核平台权限模块介绍和账号创建教程

muduo

Explore gaussdb and listen to what customers and partners say

Bit. Store: long bear market, stable stacking products may become the main theme

Cocoscreator plays audio and synchronizes progress
随机推荐
UOS prompts for password to unlock your login key ring solution
429- binary tree (108. convert the ordered array into a binary search tree, 538. convert the binary search tree into an accumulation tree, 106. construct a binary tree from the middle order and post o
一段时间没用思源,升级到最新的 24 版后反复显示数据加密问题
#夏日挑战赛# OpenHarmony HiSysEvent打点调用实践(L2)
元宇宙虚拟数字人离我们更近了|华锐互动
Redis集群
智联招聘的基于 Nebula Graph 的推荐实践分享
难怪大家丢掉了postman而选择 Apifox
redis数据结构
Connection integration development theme month | drivers of enterprise master data governance
数据库日志
Oracle architecture summary
二叉树相关问题2
[STL programming] [common competition] [Part 3]
Pyhton crawls Baidu library text and writes it into word document
Common shell script commands (III)
CocosCreator播放音频并同步进度
muduo
Database lock problem
Csdn Skills Tree use Experience and Product Analysis (1)