A_LoopField sometimes till keeps EOL

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
l6908lay
Posts: 43
Joined: 09 Apr 2023, 05:16

A_LoopField sometimes till keeps EOL

Post by l6908lay » 01 Dec 2023, 06:40

I have realized something with very large text and EOL (like `n, `r, CR+LF). if you are gaining mismatched information such as This array doesn't equal that array or this contents doesn't equal that contents. Loop Parse tends to leave in the EOL on the end of the line from a file read... To Example:

Code: Select all

FileRead, contents, filename.location
Loop, Parse, % contents, `n ; or whatever you parse by.
{
	x++
	array["here" x]:= A_LoopField ; <-------------------------- that that right there will actually still have the EOL sometimes.
}
In order to fix it:

Code: Select all

FileRead, contents, filename.location
Loop, Parse, % contents, `n ; or whatever you parse by.
{
	x++
	y:=StrLen(A_LoopField)
	y--
	newstr:= SubStr(A_LoopField, 1, y) ;<------------- substring it off.
	array["here" x]:= newstr
}

just me
Posts: 9617
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: A_LoopField sometimes till keeps EOL

Post by just me » 13 Dec 2023, 09:18

In order to fix it:

Code: Select all

Loop, Parse, % contents, `n, `r  ; or whatever you want to strip

User avatar
boiler
Posts: 17710
Joined: 21 Dec 2014, 02:44

Re: A_LoopField sometimes till keeps EOL

Post by boiler » 02 Jan 2024, 05:38

Moved from “Tips and Tricks (v1)” since the tip in the OP is not the solution, while the solution is found in the Loop, Parse documentation in two of the examples: #2 and #3.

(By the way, when you do want to remove the last character from a string using SubStr, use -1 for length parameter, which is also documented.)

Post Reply

Return to “Ask for Help (v1)”