How to read the specified line using File.ReadLine()

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

How to read the specified line using File.ReadLine()

21 Dec 2018, 04:35

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.
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: How to read the specified line using File.ReadLine()

21 Dec 2018, 05:09

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

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
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to read the specified line using File.ReadLine()

21 Dec 2018, 06:22

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
}
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: How to read the specified line using File.ReadLine()

21 Dec 2018, 11:21

Thank you. I wonder if it should work with File.Seek.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to read the specified line using File.ReadLine()

22 Dec 2018, 09:44

if what should work with File.Seek()?
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: How to read the specified line using File.ReadLine()

23 Dec 2018, 11:40

swagfag wrote:
22 Dec 2018, 09:44
if what should work with File.Seek()?
File.ReadLine()

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: effel, rc76 and 206 guests