string lua 拆分成词
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2779700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:43:59 来源:igfitidea点击:
lua split into words
提问by anon
I have a string in lua.
我在 lua 中有一个字符串。
It's a bunch of [a-zA-Z0-9]+ separated by a number (1 or more) spaces.
它是一堆 [a-zA-Z0-9]+ ,由数字(1 个或更多)空格分隔。
How do I take the string and split it into a table of strings?
如何获取字符串并将其拆分为字符串表?
回答by lhf
s="How do I take the string and split it into a table of strings?"
for w in s:gmatch("%S+") do print(w) end
回答by ponzao
s = "foo bar 123"
words = {}
for word in s:gmatch("%w+") do table.insert(words, word) end