Trying to make function which takes string as input and returns no. of words in whole string
- 阅读更多 关于 Trying to make function which takes string as input and returns no. of words in whole string
问题 **It takes Input as a string such as this - 'Nice one' And Output gives - 4,3 (which is no. Of words in sentence or string) ** 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 回答1: -- Localise for performance. local insert = table.insert local text = 'I am a