encoding - Lua - read one UTF-8 character from file -


is possible read 1 utf-8 character file?

file:read(1) return weird characters instead, when print it.

function firstletter(str)   return str:match("[%z\1-\127\194-\244][\128-\191]*") end 

function returns 1 utf-8 character string str. need read 1 utf-8 character way, input file (don't want read file memory - via file:read("*all"))

question pretty similar post: extract first letter of utf-8 string lua

function read_utf8_char(file)   local c1 = file:read(1)   local ctr, c = -1, math.max(c1:byte(), 128)   repeat     ctr = ctr + 1     c = (c - 128)*2   until c < 128   return c1..file:read(ctr) end 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -