Hello,
How to read the specified line using File.ReadLine() ?
For example, read the third line of a text file, what should I do?
Thanks.
How to read the specified line using File.ReadLine()
Re: How to read the specified line using File.ReadLine()
I have a notepad testing.txt containing this:
this is the 1st line
this is the 2nd line
this is the 3rd line
this is the 4th line
this is the 1st line
this is the 2nd line
this is the 3rd line
this is the 4th line
Code: Select all
fileread, contents, %A_Desktop%/testing.txt ;reads the notepad
loop, parse, contents, `n ;read notepad line by line
{
if a_index = 3 ;if line number = 3
line%a_index% = %a_loopfield% ;assign var
}
msgbox %line3%
;#######################################################################
exitapp
esc::ExitApp
Re: How to read the specified line using File.ReadLine()
Code: Select all
MsgBox % readLineNum(3, FileOpen("C:\mylongasstxtfile.txt", "r"))
readLineNum(lineNum, fileObj) {
Loop % lineNum
{
line := ""
readLine := fileObj.ReadLine()
Loop
{
line .= readLine
if !(StrLen(readLine := fileObj.ReadLine()) == 65535)
{
line .= readLine
continue 2
}
}
}
return line
}
Re: How to read the specified line using File.ReadLine()
Thank you. I wonder if it should work with File.Seek.
Re: How to read the specified line using File.ReadLine()
if what should work with File.Seek()?