ziomal432 Posted July 5, 2010 Share Posted July 5, 2010 I'd line to do something like INI parser, but fileRead doesn't read file line-by-line. I seen some examples to do this, but didn't worked in MTA. How to do this? Link to comment
Lordy Posted July 5, 2010 Share Posted July 5, 2010 You just read the whole file in for example and then split it from newlines. Link to comment
ziomal432 Posted July 5, 2010 Author Share Posted July 5, 2010 Ok, I used example from wiki and explode (founded in Google), works good. Thanks. If somebody would need it, here: f = fileOpen("thefile.txt", false) local FullText = fileRead(f, 100) while not fileIsEOF(f) do FullText = FullText .. fileRead(f, 100) end fileClose(f) Lines = explode("\n", FullText) for i = 1, #Lines do -- line: Lines[i] end Explode function: function explode (seperator, str) --from: [url=http://luanet.net/lua/function/explode]http://luanet.net/lua/function/explode[/url] local pos, arr = 0, {} for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found table.insert( arr, string.sub( str, pos, st-1 ) ) -- Attach chars left of current divider pos = sp + 1 -- Jump past current divider end table.insert( arr, string.sub( str, pos ) ) -- Attach chars right of last divider return arr end Link to comment
Lordy Posted July 5, 2010 Share Posted July 5, 2010 (edited) MTA has also a builtin function split for the job. https://wiki.multitheftauto.com/wiki/Split Edited July 5, 2010 by Guest Link to comment
ziomal432 Posted July 5, 2010 Author Share Posted July 5, 2010 Lol, I didn't seen it. Number of functions in MTA is awesome. Thanks. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now