简体   繁体   中英

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM