Splitting a string by another string

Hi. I wanted a working example of splitting a string by another string for UE4.16 in c++. Thank you if you answer.

TArray<FString> Out;
SomeString.ParseIntoArray(Out,TEXT(","),true);

Out array will be filled with sub-strings, 2nd argument is separator string (in this case “,”) which tells function in what places sperate the string. It’s quite heavy function so don’t use it on long text.

If you have only one or few spectator in string there more efficient functions:

FString Left, Right;
SomeString.Split(TEXT(","),&Left,&Right);

Left will be string left from first founf separator (1st argument) Right will be string on the Right of separator

You can also use RemoveFromStart and RemoveFromEnd if you want to remove any prefix or suffix

There also many functions to split based on character index, explore FString API reference for more:

2 Likes