Angel script ascii byte to string?

Discuss issues and ideas you have to configuring displays with PowerVision
dberezowski
Posts: 65
Joined: Wed Sep 08, 2010 4:03 pm

Angel script ascii byte to string?

Post by dberezowski » Tue Apr 16, 2013 5:19 pm

I have a uint8 array of numbers that contain the decimal value for an ascii character that I want to convert to a string. When I attempt to do so, the string contains the value and not a character. I want the string to end up being "ABCDE" but it ends up being "6566676869". See sloppy code example below. Any help would be appreciated.

uint8[5] foo;
string msg;

msg = "";
foo(0) = 65;
foo(1) = 66;
foo(2) = 67;
foo(3) = 68;
foo(4) = 69;
for( int i=0; I<5; i++)
{
msg += foo;
}
jpratt
Enovation Controls Development
Enovation Controls Development
Posts: 222
Joined: Mon Jun 21, 2010 11:18 am

Re: Angel script ascii byte to string?

Post by jpratt » Fri Apr 19, 2013 9:02 am

I don't know of an ez way to do this in the current release. You might poke around in the angelscript docs to see if there is a way. I'm working on making this much easier in 2.7 by allowing you to work with byte arrays more easily.
Jake Pratt
Software Development Manager
ksaenz
Enovation Controls Development
Enovation Controls Development
Posts: 263
Joined: Thu Aug 19, 2010 7:53 am

Re: Angel script ascii byte to string?

Post by ksaenz » Mon Apr 22, 2013 8:27 am

Hello dberezowski,

You were close, when you want add a character to a string by using the integer valule of the ASCII character you need to treat the string as an array of characters:

Code: Select all

msg[i] = foo[i];
You also need to make sure you have enough array elements avaible so if you start with an empty string you need to resize if before you start writing to the elements:

Code: Select all

msg.resize( foo.length() );
Regards,

ksaenz
jpratt
Enovation Controls Development
Enovation Controls Development
Posts: 222
Joined: Mon Jun 21, 2010 11:18 am

Re: Angel script ascii byte to string?

Post by jpratt » Mon Apr 22, 2013 8:36 am

Thanks ksaenz,

I learned something new too :)
Jake Pratt
Software Development Manager