【发布时间】:2011-02-16 07:21:18
【问题描述】:
我在 lua 中有一个字符串。
这是一堆 [a-zA-Z0-9]+ 由一个数字(1 个或多个)空格分隔。
如何获取字符串并将其拆分为字符串表?
【问题讨论】:
-
Split string in lua? 的可能重复项
我在 lua 中有一个字符串。
这是一堆 [a-zA-Z0-9]+ 由一个数字(1 个或多个)空格分隔。
如何获取字符串并将其拆分为字符串表?
【问题讨论】:
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
【讨论】:
%S 代表所有非空格字符。
s = "foo bar 123"
words = {}
for word in s:gmatch("%w+") do table.insert(words, word) end
【讨论】:
%w 代表所有字母数字字符。
[a-zA-Z0-9]+,其中不包括_。您可能想使用@lhf 提供的答案。