1 2 3 4 5 | local alphabet="αβγδ" print("len="..#alphabet) for i=1,#alphabet do print(string.sub(alphabet,i,i)) end |
the 24 characters of http://www.lua.org/cgi-bin/demo represent the decimal numeric values of the Greek Unicode characters
what do the ?'s of the Corona SDK respresent?
the string.byte and string.char functions can be used to compute the length and the substring of a string that contains characters other than those of the english alphabet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | string.len=function(s) local len,k=0,1 while k<=#s do len=len+1 if string.byte(s,k)<=190 then k=k+1 else k=k+2 end end return len end string.sub=function(s,i,j) local chars={} local k=1 while k<=#s do local byte1=string.byte(s,k) if byte1<=190 then chars[#chars+1]=string.char(byte1) k=k+1 else local byte2=string.byte(s,k+1) chars[#chars+1]=string.char(byte1,byte2) k=k+2 end end local sub="" for m=i,j do sub=sub..chars[m] end return sub end |
Many thanks for this post. Just made my day.
views:1646 update:2011/10/5 21:23:48