How to convert String to PoolByteArray in C++

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Filipe Coelho

I’m trying to convert from a Godot String to a PoolByteArray in C++. In GDScript, there are two methods for this (.to_utf8() and .to_ascii()), however in C++ they return a CharString that can’t be directly converted to PoolByteArray. Anyone knows how I can achieve this?

BYTE ascii_to_num(char c)
{
if (‘0’ <= c && c <= ‘9’)
return c - ‘0’;
if (‘a’ <= c && c <= ‘f’)
return c -(‘a’-(‘0’+10));
}
for(i=0,n=0; n<num ;i=i+2,n++)
{
BYTE a = (ascii_to_num(newSign[i])) & 0x0F;
BYTE b = ascii_to_num(newSign[i+1]) & 0x0F;
bSign[n] = (a<<4) | (b);
printf(“bsign[%d] is %x\n”,n,bSign[n]);
}

besttutors | 2019-12-19 15:13