byte[] to string problem

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

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

byte[] to string problem

Postby scofy » 31 Aug 2016, 06:49

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: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: byte[] to string problem

Postby Lapo » 31 Aug 2016, 08:26

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

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 20 guests