Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Excuse me, how does lua divide Chinese strings? A= "I'm from China" The result of string.len is 15? How should I read it?
Excuse me, how does lua divide Chinese strings? A= "I'm from China" The result of string.len is 15? How should I read it?
Your search string? I'm from China? If the length is 15, then this string is probably encoded in UTF-8. In UTF-8 coding, one Chinese character usually occupies 3 bytes, so five Chinese characters occupy 15 bytes.

If you can ensure that your strings are all Chinese characters and are all encoded with UTF8, you can define the following functions:

A= "I'm from China"

Function? get_chinese_char(str,? Index)

Local? Start? =? (Exponent-1)? *? 3? +? 1

Return? Str:sub(start, start? +? 2)

end

print(get_chinese_char(a,? 3));