byte[] to string problem

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

Post Reply
scofy
Posts: 79
Joined: 08 Apr 2012, 09:04

byte[] to string problem

Post by scofy »

When serverside send a string by byte[] to client like this:

Code: Select all

byte[] utf8 = str.getBytes("UTF-8");
and on client side i make string by function binl2rstr()

Code: Select all

 var len = param.readInt()
    if(len > 0){
        var nameData = []
        for(var i=0;i<len;i++){
            nameData.push(param.readByte())
        }
        ret.name = binl2rstr(nameData)
    } 
everything is ok,but Chinese characters are not displayed properly,how can i fix it?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: byte[] to string problem

Post by Lapo »

Hi,
why are you sending strings in bytes instead of just using the string type?

That way you're likely causing encoding issues. Unless there's a specific reason stick with strings and you won't have to worry about encoding.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply