# Concating strings and other things

**URL:** <https://forums.unrealengine.com/t/concating-strings-and-other-things/79077>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [November 24, 2016, 8:03am UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077 "2016-11-24T08:03:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![EniGmaa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EniGmaa](https://forums.unrealengine.com/u/EniGmaa)\
**Post date:** [November 24, 2016, 8:03am UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/1 "2016-11-24T08:03:51Z")

</div>

Hi guys got small problem but can’t figure out how to concate properly inside unreal.

Basically I have a FName variable like this  
FName name = \*requiredComponent-\>GetName();

Which works fine howether I’ve been getting crashes whenc creating multiple things and after debugging I found out the reason for the crashes is because multiple objects can’t have the same name

There fore I need a way to add for example \_01 , \_02 etc after each name the same as what unreal does

So for example say I made 2 box collision components  
First one would be name = boxCollisonComponent\_01  
Second would be name =boxCollisionComponent\_02  
Etc

But I can’t figure out how to do it.

I tried making an int that increases by 1 each time and convert that to a string and then append that to the FName variable but that didn’t work.

Thanks

---

<div class="post-metadata">

**Author:** ![ReaperLAS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ReaperLAS](https://forums.unrealengine.com/u/ReaperLAS)\
**Post date:** [November 24, 2016, 1:45pm UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/2 "2016-11-24T13:45:14Z")

</div>

I’m a bit confused. The “requiredComponent” was generated by you on code?, or is something coming from a blueprint?.

If it was generated by you manually, you could either name them differently or if generated by code add the logic to randomize the name there (or add \_01, \_02 and so on). If this is something that was generated by Unreal then shouldn’t they already have different names?.

What’s the type of requiredComponent?, just to have more info on the issue could you show a little more code?.

Alternatively, you could use FString for all the tools it provides, and if this is something that will travel through network you can later convert it to FName (minding size). Also note FName is case insensitive, so might not be the best choice for unique identification.

---

<div class="post-metadata">

**Author:** ![MykonCodes](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MykonCodes](https://forums.unrealengine.com/u/MykonCodes)\
**Post date:** [November 24, 2016, 2:13pm UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/3 "2016-11-24T14:13:12Z")

</div>

Have a look at this  
[https://wiki.unrealengine.com/String\_Conversions:\_FString\_to\_FName,\_FString\_to\_Int32,\_Float\_to\_FString](https://wiki.unrealengine.com/String_Conversions:_FString_to_FName,_FString_to_Int32,_Float_to_FString)

---

<div class="post-metadata">

**Author:** ![EniGmaa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EniGmaa](https://forums.unrealengine.com/u/EniGmaa)\
**Post date:** [November 24, 2016, 2:23pm UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/4 "2016-11-24T14:23:55Z")

</div>

Thakyou but I have already looked at that and it is very helpfull for learning straight forward conversions but what I need is a bit more complicated

As i need to convert  
FName to a string  
Pass an int variable into a string  
And then add the int variable/string onto the end of the other string .  
Then convert it all back into a FName as FName is the only variabls type that the function im using will accept as the parameter.

Also im not really struggling with the conversions but more rather the concating (adding together of the strings etc ) there was nothing in that wiki about concating strings etc and the way it works in unreal seems to differ slightly from standard c++.

Everything I try doesn’t give me any compiler errors or anything but I just cannot seem to get the desired result

Thanks

---

<div class="post-metadata">

**Author:** ![MykonCodes](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MykonCodes](https://forums.unrealengine.com/u/MykonCodes)\
**Post date:** [November 24, 2016, 2:31pm UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/5 "2016-11-24T14:31:39Z")

</div>

What about

```auto

FName name = *requiredComponent->GetName();
FString base = name.ToString();
int32 index = someIndex;
base.append("_");
base.append(FString::FromInt(index));

FName newName = FName(*base);

```

---

<div class="post-metadata">

**Author:** ![EniGmaa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EniGmaa](https://forums.unrealengine.com/u/EniGmaa)\
**Post date:** [November 24, 2016, 6:04pm UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/6 "2016-11-24T18:04:20Z")

</div>

> [@;628234](#):
>
> What about
> 
> ```auto
> 
> FName name = *requiredComponent->GetName();
> FString base = name.ToString();
> int32 index = someIndex;
> base.append("_");
> base.append(FString::FromInt(index));
> 
> FName newName = FName(*base);
> 
> ```

wow very interesting and cool way of doing it. didn’t realise there was already ‘append functions available’ to help i was trying to do it all myself.  
worked perfectly.

thanks for you’re help

---

<div class="post-metadata">

**Author:** ![MykonCodes](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MykonCodes](https://forums.unrealengine.com/u/MykonCodes)\
**Post date:** [November 24, 2016, 6:18pm UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/7 "2016-11-24T18:18:29Z")

</div>

No problem. Also you can just say fstring1 += fstring2;  
It’s even easier than calling append();

---

<div class="post-metadata">

**Author:** ![EniGmaa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EniGmaa](https://forums.unrealengine.com/u/EniGmaa)\
**Post date:** [November 25, 2016, 7:01am UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/8 "2016-11-25T07:01:45Z")

</div>

> [@;628300](#):
>
> No problem. Also you can just say fstring1 += fstring2;  
> It’s even easier than calling append();

I think that’s what I was trying in the beginning and was getting weird results which is why I said I think unreal does things differently howether looking at my old code I think the problem may have been I was declaring the int as int not int32 .  
Anyway all sorted now . Thanks again

---

<div class="post-metadata">

**Author:** ![MykonCodes](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MykonCodes](https://forums.unrealengine.com/u/MykonCodes)\
**Post date:** [November 25, 2016, 7:10am UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/9 "2016-11-25T07:10:51Z")

</div>

Hmm maybe you tried to += with the integer? Always convert other types to FString before you call +=. Not really sure, if that not should work too, but just to make sure. There are conversion functions for allmost all F variables, FRotator, FVector, FName, (.ToString()), float is FString::SanitizeFloat(floatname), int32 is FString::FromInt()

---

<div class="post-metadata">

**Author:** ![GunnerJnr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gunnerjnr/32/1205716_2.png) [@GunnerJnr](https://forums.unrealengine.com/u/GunnerJnr)\
**Post date:** [November 26, 2016, 7:45am UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/10 "2016-11-26T07:45:00Z")

</div>

Why not use an array or a dynamic array for the object creation…

> **[TArray: Arrays in Unreal Engine](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/TArrays/)**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![Willard720](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Willard720](https://forums.unrealengine.com/u/Willard720)\
**Post date:** [September 6, 2022, 5:18am UTC](https://forums.unrealengine.com/t/concating-strings-and-other-things/79077/11 "2022-09-06T05:18:59Z")

</div>

What? that sounds like its way overcomplicating the issue.
