'How do you convert an FString of delimited floats to a TArray<uint16> using Unreal C++

Given an FString of "123.2222,446.4444,55234.2342" how do you convert this to a TArray of type uint16?

Current attempt is to parse the string into an array using

TArray<FString> Parsed;
    HeightMapData.ParseIntoArray(Parsed, TEXT(","), false);

This seems to work well. Next is the problem of how do I convert this to uint16.

I am trying

const TArray<uint16*>& parsedArray = reinterpret_cast<const TArray<uint16*>&>(Parsed);

But it is not working. Error: Parent address is invalid for parsedArray



Solution 1:[1]

You can't reinterpret_cast and pretend your array of strings is an array of integers. You need to convert each string to an integer in a new array:

TArray<uint16> intArray;
for (const auto& str : Parsed)
    intArray.Add(FCString::Atoi(str));

Ref: https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/StringHandling/FString/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Zwinck