Page 1 of 1

loop read file - tab characters at beginning of line are stripped

Posted: 18 Jul 2017, 10:25
by subodhjoshi
[searched here for 'loop read file tab beginning' which did not bring up any results]

When using loop, read to read a file, the tab characters at the beginning of each line are stripped. I dont see any options to preserve them. Do not want to use FileRead and then parse the string - I do not even know if it will have this same issue. Any ideas?

Here is piece of code that I am using;

Code: Select all

Loop, read, %FromFolder%%InputFile%
{    ;; ------------------------ LOOP 58748 BEGINS

	currline = 
	currline = %A_LoopReadLine%

	;msgbox %currline%
	
	;; work on the line. If certain text strings are found in a line, modify them as needed
	;; write any lines (changed or unchanged) to a variable, separated by newline char
	
	;; write the variable to a new file

}
Thanks in advance for your time.

Re: loop read file - tab characters at beginning of line are stripped  Topic is solved

Posted: 18 Jul 2017, 10:32
by KeypressGuy
AutoTrim Off

"On: In a statement such as Var1 = %Var2%, tabs and spaces at the beginning and end of a Var2 are omitted from Var1. This is the default.
"Off: Such tabs and spaces are not omitted."

Re: loop read file - tab characters at beginning of line are stripped

Posted: 18 Jul 2017, 10:40
by boiler
I am not finding that to be the case. I just did a very simple test script, and the MsgBox showed the leading tabs from the text file.

Code:

Code: Select all

Loop, Read, test.txt
	MsgBox, % ">>>" A_LoopReadLine "<<<"
test.txt:

Code: Select all

	one leading tab
		two leading tabs
			three leading tabs

Re: loop read file - tab characters at beginning of line are stripped

Posted: 18 Jul 2017, 10:53
by subodhjoshi
@boiler: Indeed, "A_LoopReadLine" does preserve leading tabs in a line but when "currline" is assigned value of "A_LoopReadLine" , they are stripped.

@KeypressGuy: "AutoTrim off" worked like a charm - THX!

Admin - please close the thread. Unless of course there are other working solutions that would possibly be posted here.

Re: loop read file - tab characters at beginning of line are stripped

Posted: 18 Jul 2017, 18:14
by TAC109
As an alternative to AutoTrim off you can use 'expression syntax'. Replace
currline = %A_LoopReadLine% with
currline := A_LoopReadLine

Re: loop read file - tab characters at beginning of line are stripped

Posted: 21 Jul 2017, 08:34
by subodhjoshi
@TAC109: Indeed. Thx. And using := to assign variables does not trim EVEN WHEN Autotrim is set to 'on'.