본문 바로가기

Development/Unreal Engine 4, 5

Splitting a string by another string

FString::ParseIntoArray 8

Breaks up a delimited string into elements of a string array.

 
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::Split 8

Splits this string at given string position case sensitive.

 
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

 

 

RemoveFromStart 2

Overload list

 
 

RemoveFromEnd 1

Overload list

 

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

 

FString 1

A dynamically sizeable string.

 

 
 

 

https://forums.unrealengine.com​/t/splitting-a-​string-by-another-string/402117

 

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.

forums.unrealengine.com