UE4 – making an FString from FStrings and other variables
When coding in UE4, you often want to construct a string from variables. This is pretty easy using the FString::Printf
or FString::Format
functions.
Getting ready
For this, you should have an existing project into which you can enter some UE4 C++ code. Putting variables into a string is possible via printing. It may be counterintuitive to print into a string, but you can't just concatenate variables together, and hope that they will automatically convert to string, as in some languages such as JavaScript.
How to do it…
- Using
FString::Printf()
:- Consider the variables you'd like printed into your string.
- Open and take a look at a reference page of the
printf
format specifiers, such as http://en.cppreference.com/w/cpp/io/c/fprintf ...
Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.