Compare String representations in Unreal

Unreal supports many different string utilities, such as ANSICHAR, TCHAR, FString, FName, FCString, etc.
Beside reading endless API documentations, is there a high level overview that summaries all these types?

  1. How to decide which one to use.
  2. Advantages and disadvantages among these strings.
  3. Any other string representations?

Hello, KidBroker

If you need to use string manipulation, such as case changing, excerpting substrings, reversing, searching and comparing, please use FString. The main disatvange of this type is that availability of this functionality makes it more expensive than the immutable string classes.

FCString is a typedef inside of TCString class for TCHAR strings. TCString class provides a set of widely used utility functions that operate on plain C strings. There are also specialized implementations for ANSICHAR and WIDECHAR strings in TCString:

typedef TCString<TCHAR>    FCString;
typedef TCString<ANSICHAR> FCStringAnsi;
typedef TCString<WIDECHAR>  FCStringWide;

FNames represent public names, available to the world. They provide a very lightweight system for using strings, where a given string is stored only once in a data table, even if it is reused. Please note that FNames are case-insensitive. They are immutable and cannot be manipulated. The storage system and static nature of FNames means that it is fast to look up and access FNames with keys. Another feature of the FName subsystem is the use of a hash table to provide fast string to FName conversions. This type should be used when you save strings to hard drive or send them over the network since FName minimizes data storage and data transfer operations.

FText represents a “display string”. Any text you want to display to the user should be handled with FText. The FText class has built-in support for localization, and can handle text content that is localized and stored in a lookup table, as well as text that is localized at runtime, such as numbers, dates, times, and formatted text. Even text that does not need to be localized can be handled with FText. This includes user-entered content such as a player’s name, and any text displayed with Slate. FText does not offer any mutation functions, because making changes to display strings is a very unsafe operation.

In terms of size, please note that FText is 40 bytes, FString is 16 bytes and FName is only 8 bytes.

Thus, to sum up, you use FStrings if you need to manipulate a string, for example when building a URL or creating a save file name. FNames are good for asset names and material parameters. Finally, FText is used for HUD text, player names and calendar dates.

Hope this helped!

Have a great day!