tags:

views:

57

answers:

2

How can I convert a ByteArray to string. The toString() is not working as I have some special characters and it shows me only the first character.

Here is a sample:

49, 48, 54, 0, 50, 54, 51, 48, 57, 52, 52, 49, 48, 48, 48, 56, 0, 49, 0, 49, 0, 73, 77, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0, 49, 0, 50, 54, 51, 49, 53, 56, 50, 52, 48, 48, 48, 52, 0, 0, 0, 0, 49, 53, 49, 46, 48, 48, 0, 0, 70, 82, 0, 0, 0, 0, 54, 48, 55, 48, 90, 81, 57, 51, 0, 70, 82, 0, 48, 0, 70, 67, 65, 0, 76, 73, 86, 82, 89, 0, 0, 54, 48, 55, 48, 90, 81, 57, 51, 0, 70, 82, 0, 69, 85, 82, 0, 52, 50, 48, 48, 46, 48, 48, 0, 49, 0, 49, 0, 51, 48, 0, 0, 66, 65, 86, 75, 76, 0, 0, 49, 48, 49, 48, 52, 0, 0, 0, 0, 0, 49, 48, 49, 48, 54, 57, 49, 48, 49, 53, 0, 0, 0

Thanx for your time.

+1  A: 

Use String.fromCharCode:

var myStr:String = String.fromCharCode(49, 48, 54, 32, 50, 54, 51, 48, 57, 52, 52, 49, 48, 48, 48, 56, 32, 49, 32, 49, 32, 73, 77, 32, 52, 32, 32, 32, 32, 32, 32, 32, 32, 49, 32, 49, 32, 50, 54, 51, 49, 53, 56, 50, 52, 48, 48, 48, 52, 32, 32, 32, 32, 49, 53, 49, 46, 48, 48, 32, 32, 70, 82, 32, 32, 32, 32, 54, 48, 55, 48, 90, 81, 57, 51, 32, 70, 82, 32, 48, 32, 70, 67, 65, 32, 76, 73, 86, 82, 89, 32, 32, 54, 48, 55, 48, 90, 81, 57, 51, 32, 70, 82, 32, 69, 85, 82, 32, 52, 50, 48, 48, 46, 48, 48, 32, 49, 32, 49, 32, 51, 48, 32, 32, 66, 65, 86, 75, 76, 32, 32, 49, 48, 49, 48, 52, 32, 32, 32, 32, 32, 49, 48, 49, 48, 54, 57, 49, 48, 49, 53, 32, 32); 

EDIT: Replace the zero bytes 0 with 32 (space) and you will get this:

106 263094410008 1 1 IM 4 1 1 263158240004 151.00 FR 6070ZQ93 FR 0 FCA LIVRY 6070ZQ93 FR EUR 4200.00 1 1 30 BAVKL 10104 1010691015

splash
thanx @splash for the quick answer, but I am facing the same problem as when using .toString() it does not show all of the characters, any ideas why? or what else to use.
Adnan
I can't test it in the moment, but maybe a zero byte is not allowed.
splash
+1  A: 

For future reference you can convert a byte array to a Base64 string, which would be a more standard way to serialise binary to a string.

The mx library has a Base64 encoder/decoder class, but there are a few other implementations laying around....

Have a read of this article: http://jpauclair.net/2010/01/09/base64-optimized-as3-lib/

slomojo
thanx @slomojo will take a look.
Adnan