I want to split strings , but not with the default paterns like this:
for token in gmatch("lalla", [^%p]+) do
or with %a %c %d %l %w etc...
i want to do that but with a designated patern like this:
(not a real code , you know)
for token in gmatch("la:la\la.la", "\")
then the results will be : la:la and la.la
(sorry for any English error)
Split string(with a designated way to separete)
Started by lukasloko, Jun 23 2015 05:17 PM
lua help api
6 replies to this topic
#1
Posted 23 June 2015 - 05:17 PM
#2
Posted 23 June 2015 - 05:26 PM
What exactly do you mean?
#3
Posted 23 June 2015 - 05:32 PM
anything like split string with my , i choice , the term of the separation.
without use a patern like separete with ponctuation by %p
without use a patern like separete with ponctuation by %p
#4
Posted 23 June 2015 - 05:34 PM
ok, here it goes:
local function split(str,sep)
sep = sep or " "
local ret = {}
for token in str:gmatch("[^"..sep.."]+") do
ret[#ret+1] = token
end
return ret end
Edited by Creator, 23 June 2015 - 05:35 PM.
#5
Posted 23 June 2015 - 05:41 PM
so with this the result will come in a table?
I need to use the table or i can make with other thing?
I need to use the table or i can make with other thing?
#6
Posted 23 June 2015 - 05:57 PM
ok , it works , thanks
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












