UTF-8 string length problem

Hello,

How can I get the length of a UFT-8 string?
For example, the length of some chinese characters: “??”.
Because the string.len() only returns correctly when the string is english characters.

Thanks! [import]uid: 99926 topic_id: 17792 reply_id: 317792[/import]

hi,

did you check out official lua docs for unicode usage?

http://lua-users.org/wiki/LuaUnicode

there _may_ be your answer… [import]uid: 11686 topic_id: 17792 reply_id: 67935[/import]

Thanks deniz!

Yes I found what I want in that page.
For other people’s convenience, here is what I found:

You could use the following code snippet to iterate over UTF-8 sequences (this will simply skip over most invalid codes):

for uchar in string.gfind(ustring, “([%z\1-\127\194-\244][\128-\191]*)”) do
– something
end


Very useful code snippet. [import]uid: 99926 topic_id: 17792 reply_id: 67949[/import]