Lua divided into words

I have a line in lua.

This is a [a-zA-Z0-9] + heap, separated by a space (1 or more).

How to take a row and split it into a row table?

+6
string lua
source share
2 answers
s = "foo bar 123" words = {} for word in s:gmatch("%w+") do table.insert(words, word) end 
+11
source share
 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 
+34
source share

All Articles