Extract line number from clipboard / text file.

Get help with using AutoHotkey and its commands and hotkeys
Knotty_
Posts: 3
Joined: 15 Jan 2018, 05:43

Extract line number from clipboard / text file.

15 Jan 2018, 06:11

Morning All,

I'm trying to extract the line number from an auto generated text file to determine quantity of items (ie if string is on line 9 this means there is one number, if string is on line 11 this means there is 3 number).

I looked through the forums and found something similar on the archived forums:

https://autohotkey.com/board/topic/1006 ... le-please/

Below is how I have tried to implement it:

Code: Select all

F11::

Send ^a
Send ^c

string := "Subtotal"

Loop, Parse, clipboard, `r`n
{
If A_loopfield contains %string%
  {
  LineNum := A_Index
break
  }
}
MsgBox %LineNum%
return
Odd thing is it returns 15 regardless of what text file I look at (be in just an 'a' or a full text document). I use it by making the notepad window active and hitting F11.
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Extract line number from clipboard / text file.

15 Jan 2018, 06:50

Try to debug by running the code to see what whent wrong.

Code: Select all

F11::

Send ^a
Send ^c

string := "Subtotal"

Loop, Parse, clipboard, `r`n
{
If A_loopfield contains %string%
LineNum := A_Index
l .= A_Index "    "   A_LoopField "`n"
}
MsgBox linenumber= %LineNum%`n**********************`n%l%
return
soundcloud.com/user-32706894
Knotty_
Posts: 3
Joined: 15 Jan 2018, 05:43

Re: Extract line number from clipboard / text file.

15 Jan 2018, 06:58

Thanks for that, for some reason there is an additional return in the %clipboard% between lines that doesn't show in the text file.

Eg (text file):

1 sometext
2 sometext
3 sometext
4 subtotal

%clipboard%

1 sometext
2
3 sometext
4
5 sometext
6
7 subtotal
Knotty_
Posts: 3
Joined: 15 Jan 2018, 05:43

Re: Extract line number from clipboard / text file.

15 Jan 2018, 07:03

Right, turns out it was the use of 'r, it was adding returns between lines.
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Extract line number from clipboard / text file.

15 Jan 2018, 07:29

Code: Select all

Loop, Parse, clipboard, `n,`r
Probably you solved it already :)
Greetings,
soundcloud.com/user-32706894

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], cainxabel, Google [Bot], KHA, MIRKOSOFT, tmplinshi and 189 guests