简体   繁体   English

如何将分隔浮点数的 FString 转换为 TArray<uint16> 使用虚幻 C++</uint16>

[英]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?给定“123.2222,446.4444,55234.2342”的 FString,如何将其转换为 uint16 类型的 TArray?

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.接下来是如何将其转换为 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错误:parsedArray 的父地址无效

You can't reinterpret_cast and pretend your array of strings is an array of integers.您不能reinterpret_cast并假装您的字符串数组是整数数组。 You need to convert each string to an integer in a new array:您需要将每个字符串转换为新数组中的 integer:

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/参考: https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/StringHandling/FString/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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