One trick shown me that I could use bytes+""
which convert into String but not a pure String. It is acceptable by any UI components except it won't accept when I thro开发者_开发知识库w bytes+""
into switch
statement. How do I convert bytearray to pure string?
private function socketDataHandler(event:ProgressEvent):void {
try {
rsocket = event.target as Socket;
bytes = new ByteArray();
rsocket.readBytes(bytes);
kEvent(bytes+"");
rsocket.flush();
} catch (error:Error) {
Alert.show(error.message, "Error");
}
}
If your string is UTF8, you can just do the following:
var myString:String = bytes.readUTF();
You can see this in the documentation here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html
Just use toString() method.
var ba:ByteArray;
var str:String = ba.toString();
精彩评论