I have a string in lua.
It's a bunch of [a-zA-Z0-9]+ separated by a number (1 or more) spaces.
How do I take the string and split it into a table of strings?
In Lua, there is no split function that is present inside the standard library but we can make use of other functions to do the work that normally a split function would do.
Returns an iterator function that, each time it is called, returns the next captures from pattern over string s . If pattern specifies no captures, then the whole match is produced in each call.
String" local split = string. split(String,".") --"." being the character that you want to use for splitting. print(split) local FirstWord = split[1] --Access the first word from the split string. local SecondWord = split[2] --Acces the second word from the split string, etc etc.
s = "foo bar 123"
words = {}
for word in s:gmatch("%w+") do table.insert(words, word) end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With