2010-10-01 112 views
2

如何將ByteArray轉換爲字符串。 toString()不工作,因爲我有一些特殊字符,它只顯示第一個字符。Flex:ByteArray to string

這裏有一個例子:

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 

感謝名單的時間。

回答

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

編輯:替換32(空間)的零個字節0,你會得到這樣的:

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

+0

感謝名單@splash的快速解答,但是我面臨着與使用.toString()時相同的問題,它不顯示所有的字符,有什麼想法爲什麼?或者還有其他什麼用途。 – Adnan 2010-10-01 19:03:55

+0

我現在無法測試它,但可能不允許零字節。 – splash 2010-10-01 19:07:02

1

爲了將來的參考,你可以將一個字節數組轉換成一個Base64字符串,這將是一個更爲標準的將二進制串行化爲字符串的方式。

對MX庫有一個Base64編碼器/解碼器類,但也有一些其他的實現奠定左右....

對這篇文章的讀:http://jpauclair.net/2010/01/09/base64-optimized-as3-lib/

+0

thanx @slomojo會去看看。 – Adnan 2010-10-02 14:56:42