Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lua split into words

Tags:

string

lua

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?

like image 870
anon Avatar asked May 06 '10 08:05

anon


People also ask

How do you split Lua?

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.

What is Lua Gmatch?

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.

How do you split a string on Roblox?

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.


1 Answers

s = "foo bar 123"
words = {}
for word in s:gmatch("%w+") do table.insert(words, word) end
like image 195
ponzao Avatar answered Sep 30 '22 17:09

ponzao