 |
Cheat Engine The Official Site of Cheat Engine
|
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 10:46 am Post subject: Lua I/O question. |
|
|
I want to read stuff from a txt file with the name "123".
For example, in 123.txt, the characters are:
Code: |
abcd
efgh
ijkl
mnop
|
To be more specific, there are four lines and each line has 4 characters. If I want to read the third character of each line. How to do that? I only know I may need to use "io.line" combined with "io.read".
Now I use io.read() to read the whole file and then use "string.sub()" to read the third characters of each line by manually counting their position in the file, for example "c = #t +3", "g = #t +8", #t is the length of all the characters. It must be a better way than this.
Thanks in advance.
|
|
Back to top |
|
 |
Redouane Master Cheater
Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Fri Apr 15, 2016 11:23 am Post subject: Re: Lua I/O question. |
|
|
fmanager wrote: | I want to read stuff from a txt file with the name "123".
For example, in 123.txt, the characters are:
Code: |
abcd
efgh
ijkl
mnop
|
To be more specific, there are four lines and each line has 4 characters. If I want to read the third character of each line. How to do that? I only know I may need to use "io.line" combined with "io.read".
Now I use io.read() to read the whole file and then use "string.sub()" to read the third characters of each line by manually counting their position in the file, for example "c = #t +3", "g = #t +8", #t is the length of all the characters. It must be a better way than this.
Thanks in advance. |
Code: | local file = io.open('123.txt','r');
for line in file:lines() do
print('third character is '..line:sub(3,3))
end |
|
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Fri Apr 15, 2016 11:25 am Post subject: Re: Lua I/O question. |
|
|
Redouane wrote: | fmanager wrote: | I want to read stuff from a txt file with the name "123".
For example, in 123.txt, the characters are:
Code: |
abcd
efgh
ijkl
mnop
|
To be more specific, there are four lines and each line has 4 characters. If I want to read the third character of each line. How to do that? I only know I may need to use "io.line" combined with "io.read".
Now I use io.read() to read the whole file and then use "string.sub()" to read the third characters of each line by manually counting their position in the file, for example "c = #t +3", "g = #t +8", #t is the length of all the characters. It must be a better way than this.
Thanks in advance. |
Code: | local file = io.open('123.txt','r');
for line in file:lines() do
print('third character is '..line:sub(3,3))
end |
|
Thank you so much, I have been stuck with this issue for a while.
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|