Read text after line in clipboard with multiple values Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xmachinery
Posts: 15
Joined: 14 May 2016, 21:25

Read text after line in clipboard with multiple values

16 Jan 2018, 10:25

Hello,

I want to get data from clipboard.

Code: Select all

The data is like:
line 1 Text 1
line 2 Text 2
line 3 Text 3
line 4 Full Name+
line 5 Jon Snow
line 6 Text 6
line 7 Text 7
line 8 Ticket ID+
line 9 01234567890
line 10 text 10
line 11 Summary
line 12 this is a sample summary
line 13 text 13
etc.
Basically, I want to get "Jon Snow", "01234567890", and "this is a sample summary"
The line in which the variables that I want to get is random, so A_Index will not work in this case.

My code looks like this:

Code: Select all

!b::
Send, ^c
FN := "Full Name+"
TID := "Ticket ID+"
Sum := "Summary"
Status := 0
Loop, Parse, Clipboard, `n, `r
{
  
  if Status
    {
    MsgBox %A_LoopField%
    Break
    }

  else if InStr(A_LoopField, FN)
  Status := 1
}
This works, but I am only able to get Full Name. I also want to get the TicketID (TID) and the Summary (Sum). How can I do that?

Thank you!
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: Read text after line in clipboard with multiple values  Topic is solved

16 Jan 2018, 11:29

example

Code: Select all

line 5 Jon Snow
line 9 01234567890
line 12 this is a sample summary

Code: Select all

#warn
e:=""
data=
(
line 1 Text 1
line 2 Text 2
line 3 Text 3
line 4 Full Name+
line 5 Jon Snow
line 6 Text 6
line 7 Text 7
line 8 Ticket ID+
line 9 01234567890
line 10 text 10
line 11 Summary
line 12 this is a sample summary
line 13 text 13
etc.
)
FN := "Full Name+"
TID := "Ticket ID+"
Sum := "Summary"
status:=0
loop,parse,data,`n,`r
{
x:=a_loopfield
if status
   {
   e .= x . "`r`n"
   status:=0
   continue
   }
if instr(x,FN)
   status:=1
if instr(x,TID)
   status:=1
if instr(x,SUM)
   status:=1
}
msgbox,%e%
return
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Read text after line in clipboard with multiple values

16 Jan 2018, 13:38

Another way to parse your clipboard content.

Code: Select all

arr := StrSplit(clipboard,"`n")
loop, % arr.length() {
   if ( RegExMatch(arr[a_index],"Full Name+|Ticket ID+|Summary") )
      strx .= RegExReplace(arr[a_index+1], "line \d*") "`n"
}
msgbox %strx%
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: Read text after line in clipboard with multiple values

17 Jan 2018, 02:45

@Odlanir , thank you , with REGEX is the script really short

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS and 337 guests