我有一张桌子,里面有像
" item", " item"
这样的字符串。用缩进呈现此项目。我想要一种方法来分割这个字符串并计算字符串开头有多少个空格。
我就是你要找的东西?
local original = " test"
local trimmed = original:match( "^%s*(.*)" )
local spaces = #original - #trimmed
print("The original word is [" .. original .. "] and the trimmed word is [" .. trimmed .. "] and there are " .. spaces .. " spaces.")
输出:
The original word is [ test] and the trimmed word is [test] and there are 4 spaces.