Manipulating FName and FString


I would really like some help about the FName class.

What would be the best way to convert a FString to an FName ?

In my current work I would like to get some socket locations within a for loop. Unfortunately I didn’t found a way to append a number to a FName, or to append it to a FString and create a FName from this FString. Under FName, there is the function ToString() but I didn’t see a similar one (like ToName()) under FString.

Here’s answer for you!

To convert FString to FName :

 FString TheFString = "Yippee!";
 FName myConveredFString = FName(*TheFString);

The FString * operator gets the tchar* data
which is used in FName constructor

ex 1: I had to convert FString to FName and back again due to server parameter compile error (should be fixed soon), here’s my working code sample

GRI .h

UFUNCTION(reliable, server)
 void SERVER_ChatToGRI(FName ReceivedText);

controller or anywhere.cpp

FString ChatswithName = "Happy Day";
GRI->SERVER_ChatToGRI(FName( *ChatswithName));

then to convert FName back to string

FString ReceivedString = ReceivedText.ToString();

ex 2: useful any time a function wants tchar not FString*

 void Class::Function(FString& FullFilePath)
   // static bool LoadFileToArray( TArray& Result, const TCHAR* Filename)
    FFileHelper::LoadFileToArray(CompressedData, *FullFilePath);

Converting FName to FString

    FString MyConvertedFName = TheFName.ToString(); 

have fun!


Thanks a lot for the deep explanation ! :smiley:

The code:


Is the correct way to do that. Note that if you are sending things like chat messages you want to use FString not FName because you will not be comparing them etc.