lua 判断string是否含有数字

如题所述

-- 如果待判断的是一个变量

local t = type(x);
if t == "number" then
-- 是数字
else if t == "string" then
-- 是字符串
end

-- 如果带判断是一个字符串,要判断是否可以转成数字, 则
local n = tonumber(x);
if n then
-- n就是得到数字
else
-- 转数字失败,不是数字, 这时n == nil
end
温馨提示:答案为网友推荐,仅供参考
相似回答