Howto set character encoding in actionscript 3 soc

2019-08-30 22:23发布

After asking "Do certain characters take more bytes than others?", I figured out that I'd need to set the character encoding set when receiving and sending data with a socket connection in Actionscript / Flex 3.

Now I've been trying to find out how to do this, however there doesn't seem to be such property available. Is there any special way of doing this?

2条回答
够拽才男人
2楼-- · 2019-08-30 22:56

The flash.net.Socket class is a binary input/output class. You do not specify the encoding for the socket itself because you have low-level access to the data in the socket.

What you're looking for is the Socket::readMultiByte method for reading strings from different character sets.

public function readMultiByte(length:uint, charSet:String):String

Likewise, use Socket::writeMultiByte for writing strings from a specific character set.

public function writeMultiByte(value:String, charSet:String):void
查看更多
疯言疯语
3楼-- · 2019-08-30 23:08

As far as I know, Flash supports only Unicode... though there is the option to use the OS's code page with System.useCodePage. But it will depend on the user's OS and language, and is not recommended unless you know exactly what you are doing.

As for using less bytes per character, I understand that alphanumeric characters use only one byte in UTF-8 .

Cheers...

查看更多
登录 后发表回答