第一个问题。Lua中确定字符串中的最后一个字符是否不是多字节的最简单方法是什么。或者从字符串中删除最后一个字符的最简单方法是什么。
以下是有效字符串的示例,以及我希望函数的输出是什么
hello there     --- result should be:   hello ther
anñ             --- result should be:   an
כראע            --- result should be:   כרא
ㅎㄹㅇㅇㅅ       --- result should be:   ㅎㄹㅇㅇ
我需要类似的东西
function lastCharacter(string)
    --- some code which will extract the last character only ---
    return lastChar
end
或者如果它更容易
function deleteLastCharacter(string)
--- some code which will output the string minus the last character --- 
    return newString
end
这就是我要走的路
local function lastChar(string)
    local stringLength = string.len(string)
    local lastc = string.sub(string,stringLength,stringLength)
    if lastc is a multibyte character then
        local wordTable = {}
        for word in string:gmatch("[\33-\127\192-\255]+[\128-\191]*") do
            wordTable[#wordTable+1] = word
        end
    lastc = wordTable[#wordTable]
end
    return lastc
end