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;
}
Angel script ascii byte to string?
- dberezowski
- Posts: 65
- Joined: Wed Sep 08, 2010 4:03 pm
- jpratt
- Enovation Controls Development
- Posts: 222
- Joined: Mon Jun 21, 2010 11:18 am
Re: Angel script ascii byte to string?
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
Software Development Manager
- ksaenz
- Enovation Controls Development
- Posts: 263
- Joined: Thu Aug 19, 2010 7:53 am
Re: Angel script ascii byte to string?
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:
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:
Regards,
ksaenz
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];
Code: Select all
msg.resize( foo.length() );
ksaenz
- jpratt
- Enovation Controls Development
- Posts: 222
- Joined: Mon Jun 21, 2010 11:18 am
Re: Angel script ascii byte to string?
Thanks ksaenz,
I learned something new too
I learned something new too
Jake Pratt
Software Development Manager
Software Development Manager