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

Get help with using AutoHotkey and its commands and hotkeys
subodhjoshi
Posts: 5
Joined: 26 Nov 2015, 07:06

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

18 Jul 2017, 10:25

[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.
KeypressGuy
Posts: 16
Joined: 17 Jul 2017, 16:55

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

18 Jul 2017, 10:32

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."
User avatar
boiler
Posts: 7664
Joined: 21 Dec 2014, 02:44

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

18 Jul 2017, 10:40

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
subodhjoshi
Posts: 5
Joined: 26 Nov 2015, 07:06

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

18 Jul 2017, 10:53

@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.
TAC109
Posts: 651
Joined: 02 Oct 2013, 19:41
Location: New Zealand

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

18 Jul 2017, 18:14

As an alternative to AutoTrim off you can use 'expression syntax'. Replace
currline = %A_LoopReadLine% with
currline := A_LoopReadLine
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
subodhjoshi
Posts: 5
Joined: 26 Nov 2015, 07:06

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

21 Jul 2017, 08:34

@TAC109: Indeed. Thx. And using := to assign variables does not trim EVEN WHEN Autotrim is set to 'on'.

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, Elgin, jaaypeso24, kavkav123, mikeyww, Smile_ and 51 guests