"\n" epxplode

Is there a way to explode a string that contains breaks like this :


Deaths.txt

as
asd
asdf
asdff


and then il do this

PrintTable(string.explode("
",file.Read(“deaths.txt”)))

It gives me 1 =

Then stops. Anyone ?

I would also like to know this.

string.Explode not string.explode.

includes\util.lua:35: bad argument #1 to ‘pairs’ (table expected, got nil)

This happens when I use string.Explode and both of them have syntax hilighting in luapad :open_mouth:

Put this at the top of your script
[lua]function string.asplode(str,seperator)
local ret = {}
for match in string.gmatch(str,"[^("…seperator…")]*") do
if match ~= “” then
table.insert(ret,match)
end
end
return ret
end[/lua]
then in use it like this:
[lua]PrintTable( string.asplode( file.Read(“deaths.txt”), "
" ) )[/lua]

Thanks for your help, but I just found a fix.
[lua]
local contents = file.Read(“deaths.txt”)
PrintTable(string.Explode("
",contents))
[/lua]
You have to first put it in a variable before using it :S.

Please use mine. It’s more efficient than string.Explode, works with the string metatable and has a cooler name.

Asplode xD

He’s right, it is more efficient. I don’t want to start preaching, but people who learn bad efficiency techniques when they start coding end up being bad efficiency coders later on.