UTF8 array or list [SOLVED]

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

UTF8 array or list [SOLVED]

Post by atout66 » Tue Apr 01, 2014 7:34 am

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:
Last edited by atout66 on Tue Apr 01, 2014 10:32 am, edited 1 time in total.
Discovering LiveCode Community 6.5.2.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: UTF8 array or list

Post by Mark » Tue Apr 01, 2014 9:03 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: UTF8 array or list

Post by atout66 » Tue Apr 01, 2014 10:31 am

Thanks a lot Mark :wink:
Discovering LiveCode Community 6.5.2.

Post Reply