Parsing clipboard partially Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Parsing clipboard partially

28 Aug 2019, 05:28

Hello all,

I am using this to parse the clipboard:

Code: Select all

Loop, Parse, Clipboard, `n
Data%A_Index% := A_LoopField
So, now i need to find the line where the text "message" is and output the next line to a var.
I can output it directly by using:

Code: Select all

msgbox, %Data12%
But i wanted it to search for the word "message" (in this case on line 11) and output the following line (12) to a var.

I know it is probably really simple, but i am working for too many hours now and it is looping my head..
:headwall:

Ideas?
garry
Posts: 2547
Joined: 22 Dec 2013, 12:50

Re: Parsing clipboard partially  Topic is solved

28 Aug 2019, 07:06

an example , here with variable cc for test

Code: Select all

searchx=message
e:=""
i=0
cc=
(
1-aaaa
2-bbbb
3-cccc message
4-dddd followed-line
5-eeee
6-ffff
7-gggg message
8-hhhh followed-line
9-iiii
)

loop,parse,cc,`n,`r           ;- parse each line
 {
 x=%a_loopfield%
 i++
 if x contains %searchx%
    {
    a=1
    continue
    }
 if a=1
    {
    e .= x . " `;- line-" . i . "`r`n"
    a=0
    }
 }
msgbox,%e%
e=
return
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Parsing clipboard partially

28 Aug 2019, 08:02

Thank you! Very interesting solution, i will work with that! :D

Much appreciated :clap:
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Parsing clipboard partially

28 Aug 2019, 08:22

You can also use an array:

Code: Select all

searchx := "message"
cc=
(
1-aaaa
2-bbbb
3-cccc message
4-dddd followed-line
5-eeee
6-ffff
7-gggg message
8-hhhh followed-line
9-iiii
)
Arr := StrSplit(cc, "`n")
for k, v in Arr
   str .= ( v ~= searchx) ? Arr[k+1] "`n" : ""
MsgBox %str%
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
garry
Posts: 2547
Joined: 22 Dec 2013, 12:50

Re: Parsing clipboard partially

28 Aug 2019, 10:17

Odlanir, thank you for the array example , easier, shorter

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, alexsu, Bing [Bot], famko, Muzzy and 41 guests