【发布时间】:2021-01-25 08:36:27
【问题描述】:
**它将 Input 作为这样的字符串 - 'Nice one' 并且输出给出 - 4,3(这是没有。句子或字符串中的单词) **
function countx(str)
local count = {}
for i = 1, string.len(str) do
s = ''
while (i<=string.len(str) and string.sub(str, i, i) ~= ' ' ) do
s = s .. string.sub(str, i, i)
i = i+1
end
if (string.len(s)>0) then
table.insert(count,string.len(s))
end
end
return table.concat(count, ',')
end
【问题讨论】:
-
'Nice one' 中有 2 个单词。我认为您的意思是“输出字符串中单词的长度”。
标签: lua