Flex:ByteArray to string

时间:2010-10-01 18:51:51

标签: flex bytearray

如何将ByteArray转换为字符串。 toString()无效,因为我有一些特殊字符,它只显示第一个字符。

以下是一个示例:

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你的时间。

2 个答案:

答案 0 :(得分:1)

使用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); 

编辑:用0(空格)替换零字节32,您将得到:

  

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

答案 1 :(得分:1)

为了将来参考,您可以将字节数组转换为Base64字符串,这是将二进制序列化为字符串的更标准方法。

mx库有一个Base64编码器/解码器类,但还有其他一些实现......

阅读本文:http://jpauclair.net/2010/01/09/base64-optimized-as3-lib/