View previous topic :: View next topic |
Author |
Message |
Dr.Disrespect Grandmaster Cheater Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Fri Apr 15, 2016 6:20 pm Post subject: Lua I/O question No.2: specific line index? |
|
|
Is there a way to get the specific line index? or something can return the line index that shows at which line the program is. For example, I want to read the third line in a txt file, is there a function for that?
Thanks in advance.
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Fri Apr 15, 2016 8:35 pm Post subject: |
|
|
Code: | local file = io.open("myfile.txt", "r")
local option = {}
for line in file:lines() do
table.insert(option, line)
end |
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Sat Apr 16, 2016 1:50 am Post subject: |
|
|
Alternatively use a stringlist, load the textfile and then get line 2
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Redouane Master Cheater Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Sat Apr 16, 2016 5:26 am Post subject: |
|
|
Zanzer wrote: | Code: | local file = io.open("myfile.txt", "r")
local option = {}
for line in file:lines() do
table.insert(option, line)
end |
|
Or this (because the 3rd line isn't too far from the beginning):
Code: |
local file = io.open('myfile.txt','r');
local content = file:read'a'; -- read all the content of file
print(s:match'^.-\n.-\n([^\n]+)'); -- that is, skip first and second line, and print the 3rd one. |
|
|
Back to top |
|
|
Dr.Disrespect Grandmaster Cheater Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Sat Apr 16, 2016 1:15 pm Post subject: |
|
|
Sorry for the late reply, guys. Thanks a lot for all the help.
|
|
Back to top |
|
|
|