• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

string.implode(trable,var) and more.

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
bearpaw.png

Mock​
This it's an PHP emulation xp
Not unsefull but funny.

Lua:
function string.impode(arr,sep) --- by Mock
   local str = ""
   sep = sep or ""
   for i=1,#arr do
      str = str..tostring(arr[i])..sep
   end
   return str:sub(1,str:len()-1)
end
This do it:
Lua:
text = string.impode({'hi','my','name','its',false,print},'+') 
print(text)
Print->hi+my+name+its+false+function: 004C1C08

It's opossit of string.explode.

------------------------------------------
array
If you use PHP you know, arrays you must need use: array($v1,$v2,$v3,...)
now in lua you can do it! xD
i do it because i'm bored.
prepare yourself to see most biggest wrold function!
Lua:
function array(...) -- By mock
   return {...}
end
I know! UNLESS! xD
Using it:
Lua:
table_ = array(cid,name,pos,var)
print('My name is: '..table_[2])

:D
 
Code:
string.implode = function (arr, sep) -- by elf
   local str, sep = "", sep or ""
   for k, v in pairs(arr) do
      if(tonumber(k) == nil) then
         str = str .. tostring(k) .. "=>"
      end

      str = str .. tostring(v) .. sep
   end
   return str:sub(1, str:len() - 1)
end
 
It is more efficient to use table.concat to concat your strings (since a string is an array of chars) than using "..".
 
Back
Top