# Can I use switch case in C++ with FString?

**URL:** <https://forums.unrealengine.com/t/can-i-use-switch-case-in-c-with-fstring/404369>\
**Category:** Platform & Builds\
**Tags:** Switch, fstring, unreal-engine, xml, CPP, question\
**Created:** [September 12, 2017, 6:04am UTC](https://forums.unrealengine.com/t/can-i-use-switch-case-in-c-with-fstring/404369 "2017-09-12T06:04:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rigmania](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rigmania](https://forums.unrealengine.com/u/rigmania)\
**Post date:** [September 12, 2017, 6:04am UTC](https://forums.unrealengine.com/t/can-i-use-switch-case-in-c-with-fstring/404369/1 "2017-09-12T06:04:15Z")

</div>

Hi, I’m making XML parsing code with FXmlNode.  
I want to iterate through GetChildrenNodes(), and use switch-case with FString which is return value of FXmlNode::GetTag().  
Is there someway to do that? Or should I use

```
if (Tag == TEXT("XX") ..
else if (Tag == TEXT("YY"));

```

Thanks.

---

<div class="post-metadata">

**Author:** ![ZkarmaKun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zkarmakun/32/1194545_2.png) [@ZkarmaKun](https://forums.unrealengine.com/u/ZkarmaKun)\
**Post date:** [September 12, 2017, 1:49pm UTC](https://forums.unrealengine.com/t/can-i-use-switch-case-in-c-with-fstring/404369/2 "2017-09-12T13:49:36Z")

</div>

Well no, it is a limitation from FString, and every string type in UE, but you can use a trick, you can make a TArray with FNames from your FStrings, then set a number for everyone, and then get every number in the switch, but to be honest just use if and else, is less annoying.

```
FString hey = "hey";
FName ConvertedFString = FName(*hey);
	
switch (ConvertedFString.GetNumber())
{
	case 1:
	{

	}
}
```

---

<div class="post-metadata">

**Author:** ![rigmania](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rigmania](https://forums.unrealengine.com/u/rigmania)\
**Post date:** [September 13, 2017, 2:22am UTC](https://forums.unrealengine.com/t/can-i-use-switch-case-in-c-with-fstring/404369/3 "2017-09-13T02:22:05Z")

</div>

Thanks. It helps.
