如何从 NXC 中的函数返回数组?我尝试了以下
string[] strsplit(string str)
{
string parts[2] = {"1", "2"};
return parts;
}
但我明白了Variable name expected
。为什么?
PS如果有内置的拆分功能,我会很高兴在这里介绍一下。
string[]
cannot be a return type in C or C++, and hence NXC.
See the NXC API for SubStr()
, to help in 'splitting' strings.
Try:
void strspilt(string &out[], string str, unsigned int idx)
{
ArrayInit(out, "", 2);
out[0] = SubStr(str, 0, idx);
out[1] = SubStr(str, idx, strlen(str) - idx);
}