How does ParseIntoArray work in C++?

Hi All

Can someone give me a very quick illustration of how ParseIntoArray is used in C++? I can’t seem to get it to work. I think the problem may be how I’m declaring the const TCHAR delimitor…

Thanks!

looks like this works;

const TCHAR *delim;
delim = TEXT("%")

Hi,

For the single delimiter version of the function:

FString Str = TEXT("Parse,Into,Array,,Example");
TArray<FString> Parsed;
Str.ParseIntoArray(&Parsed, TEXT(","), false);
// Parsed now contains ["Parse", "Into", "Array", "", "Example"]

If you had passed ‘true’ instead of false, the empty string would be missing from the array.

The multi-delimiter version of the function looks like this:

FString Str = TEXT("Parse,Into...Array--Example");
const TCHAR* Delims[] = { TEXT("-"), TEXT("..."), TEXT(",") };
TArray<FString> Parsed;
Str.ParseIntoArray(&Parsed, Delims, 3);
// Parsed now contains ["Parse", "Into", "Array", "Example"]

In this variant, each of the specified delimiters can split the string, and empty strings (e.g. delimited by the two dashes) are never added to the array.

Hope this helps,

Steve

2 Likes

Hey,I get next error

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2664	'int32 FString::ParseIntoArray(TArray<FString,FDefaultAllocator> &,const TCHAR **,int32,bool) const': cannot convert argument 1 from 'TArray<FString,FDefaultAllocator> *' to 'TArray<FString,FDefaultAllocator> &'	SacredCards	~\Private\BasePlayerState.cpp	442

Since this question was answered, the API to ParseIntoArray has changed to take a TArray reference instead of a pointer. The above example code should now just use Parsed instead of &Parsed.

Hope this helps,

Steve

3 Likes