String Conversions: FString to FName, FString to Int32, Float to FString
Guide on String conversions (from/to) by Rama the legend
Last updated
Was this helpful?
Guide on String conversions (from/to) by Rama the legend
Last updated
Was this helpful?
Content
Original Author: Rama
Below are conversions for the following types: 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 8. Optimization Issues Concerning FNames
All the header files I refer to in this tutorial are found in
you will probably want to do a search for them from this point :)
Say we have
To convert this to an FName you do:
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
(note Atoi is unsafe; no way to indicate errors)
Note that Atoi and Atof are static functions, so you use the syntax FCString::TheFunction to call it :)
Static functions in the UnrealString.h :)
See CString.h for more details and other functions like
For a great deal of helpful functions you will also want to look at UnrealString.h for direct manipulation of FStrings!
FNames are inherently fast, but you could be forcing a hashmap lookup if you are accessing them in the wrong way. Look at the following code:
This code will take the character string "MyFNameActor_Tag" and then look it up in the FName hashmap. Whereas this code doesn't need to do a string conversion:
In our testing with UE4 4.14, the second method is nearly 100 times faster than using the string lookup. So please, always use the static const FName method over the TEXT() method. For more info on FNames check out
Enjoy!
Original author: Rama <3 Minor Authors: Kory Captured from the epic wiki via the Wayback Machine. Reformatted by DarioMazzanti
You will find this particularly useful in cases other than float and int32! C++ std::String::to_string