Unicode Problem

Sarah Reichelt sarah.reichelt at gmail.com
Wed Jan 16 20:22:53 EST 2008


> I'm reading a string from a file that is stored in Unicode (2-byte)
> format. I need to convert it to one byte characters in order to write
> the string to a database which is later sent to the server.
>
> When I execute the following it gives unexpected results
>
> put uniDecode(myStringData,"ANSI") into myStringData
>
> For instance, before executing the above, myStringData contained the
> following (in Decimal):
>
> 84 0 104 0 101 0 32 0 65 0 108 0 103 0 101 0 98 0 114 0 97 0 105 0
> 115 0 116 0
>

Hi Dave,

This doesn't look like real Unicode text but the ASCII codes for each
character with 2 bytes per character in case they are unicode. Since
every 2nd number is zero, none of them actually translate to unicode
characters.

I wrote a very quick & dirty routine to translate this into text:

on mouseUp
    put fld "Raw" into tRaw
    put empty into tConverted

    repeat with x = 1 to the number of words in tRaw step 2
        put numtochar(word x of tRaw) after tConverted
    end repeat

    put tConverted into fld "Converted"
end mouseUp

which gives me "The Algebraist



More information about the use-livecode mailing list