Display Longest Lines Length and Content of ReadFile variable Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Display Longest Lines Length and Content of ReadFile variable

30 Jul 2020, 14:02

Hi,
I have a very long txt file to be imported into a database, and I need to define the longest possible field, VarChar(??)
I would like to Loop, Parse the var myF to get and MsgBox the longest number and content of longest line.

So far I have this. Sadly, I have forgotten how to Parse with incrementing var.

Code: Select all

FileRead, myF, myList.txt
;Get and Display length and content of Longest line in file.
myL =
myT =

Loop, Parse, myF, `n, `r 
{
if (StrLen(A_LoopField) > StrLen(myL)) {

myL :=  StrLen(A_LoopField) 

myT = %A_LoopField%

continue
}
else
{
myL := StrLen(A_LoopField)
}

}

MsgBox, 4096,, Longest myList.txt Line Content is: %myT% -  Longest Line Length is: %myL%
ExitApp
I know it is way off, but this is a start.
Somehow you can Loop and keep, yet increment the detection vars.

Thanks,
Last edited by BoBo on 30 Jul 2020, 15:05, edited 1 time in total.
Reason: Added [code][code]-tags.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Display Longest Lines Length and Content of ReadFile variable

30 Jul 2020, 15:27

Code: Select all

FileRead, myF, myList.txt
psl := 0 

Loop, Parse, myF, `n, `r 
	{	
	        if (StrLen(A_LoopField) > psl) {
			psl := StrLen(A_LoopField)
			ln	:= A_LoopField
			}
	}

MsgBox % "Longest myList.txt line content is:`t" ln "`nLongest Line Length is:`t" psl
ExitApp
Not tested.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: Display Longest Lines Length and Content of ReadFile variable  Topic is solved

31 Jul 2020, 15:42

Hi Thanks Bobo,

Thanks works great. Saved me a lot of time updating some stragglers in an 850,000+ txt file.
It helped me add a new class of situation to auto-edit Postal Codes.
Then I'll run it again until I have them all.
Thanks a lot

Thanks ahk7, I reviewed that link. It was helpful too. I never trusted sorting with AHK.
Maybe I'll give it a try if I need to find many many more of these odd balls.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 376 guests