Page 1 of 1

UTF8 array or list [SOLVED]

Posted: Tue Apr 01, 2014 7:34 am
by atout66
Hi to all,

Is there a way to get a list or an arrray of UTF 8 characters ?
For example, with ASCII, we can use this script from a LC's lesson to retreive the correct ASCII number for each char:

Code: Select all

on mouseUp
   put empty into field "ascii"
   repeat with i = 0 to 255
      put i & tab & numToChar(i) & crlf after fld "ascii"
   end repeat
end mouseUp
OK. Can we do the same for UTF8 ? On the same model, I tried this code:

Code: Select all

on mouseUp
   put empty into field "UTF8"
   set the useUnicode to true
   repeat with i = 0 to 780 -- just to try
      put i & tab & charToNum(the unicodeText of i) & cr after field "UTF8"
   end repeat
end mouseUp
but I get an error message when running the script. It 'says'; Execution error at line n/a (Chunck: error in object expression) near "0", char 1.
As I can see on the dictionary, i guess it's about <charToNum(the unicodeText of i)>

Any idea would be much appreciated :wink:

Re: UTF8 array or list

Posted: Tue Apr 01, 2014 9:03 am
by Mark
Hi,

the unicodeText of 0

is incorrect syntax. Also, useUnicode uses UTF16 and not UTF8. Using UTF16 You can try this:

Code: Select all

put uniEncode(tab) into myUcTab
put uniEncode(cr) into myUcReturn
set the useUnicode to true
repeat with myCharNr = 1 to 780
  put uniEncode(myCharNr) & myUcTab & numToChar(myCharNr) & myUcReturn after myUnicodeList
end repeat
set the unicodeText of fld "Unicode" to myUnicodeList
Kind regards,

Mark

Re: UTF8 array or list

Posted: Tue Apr 01, 2014 10:31 am
by atout66
Thanks a lot Mark :wink: