Page 1 of 1

Creating Listings From Clipboard

Posted: 15 Feb 2018, 20:24
by PercyPierce
Hi Guys! How was your Valentines Day!

I am trying to create a script where autohotkey searches for a certain text, and then pastes text that comes following the last letter of what was found.

Here's an example:

Section: 213
Row: 13
Seat: 9-12
Confirmation Number: 70-30642/NY1
Order Summary: $755.00

Ok. Now here's my code so far:

Code: Select all

#persistent

Haystack := clipboard ; I copy that whole example above into the clipboard
Needle1 = InStr(Haystack, SEC, False, 3)
Needle2 = InStr(Haystack, ROW, False, 3)
Needle3 = InStr(Haystack, SEAT, False, 3)
Needle4 = InStr(Haystack, Confirmation Number, False, 3)
Needle5 = InStr(Haystack, Order Summary, False, 3)


^b:: ;paste the specified words that were found in the clipboard
If InStr(Haystack, Needle1)
  SendInput, %Needle1% ;I want the program to paste "213"
  SendInput, %Needle2%  ;I want the program to paste "13"
   SendInput, %Needle3%  ;I want the program to paste "9-12"
    SendInput, %Needle4%  ;I want the program to paste "70-30642/NY1"
     SendInput, %Needle5% ;I want the program to paste "$755.00"
return

Now my problem with this code is that it keeps pasting the position of the string instead of the WORD.
How do I get ahk to paste the WORD of the found string and not the position in number format?

Re: Creating Listings From Clipboard

Posted: 15 Feb 2018, 21:58
by Exaskryz
Note that your SEC, ROW, SEAT, Confirmation Number, Order Summary are all blank values here, because you didn't pass them as strings.

RegExMatch() has an output parameter to capture the matching needle. You can then break it up by specifying a certain portion to be captured in a pseudo-array.

(I'm going to skip making the Haystack variable; we'll just work off the clipboard)

To start you off:

Code: Select all

RegExMatch(clipboard,"Section: (\d+)",sec)
MsgBox %sec1% ; try it with "sec" only and see that the word "Section: " is included.

Re: Creating Listings From Clipboard

Posted: 16 Feb 2018, 09:47
by Odlanir

Code: Select all

var = 
(
Section: 213
Row: 13
Seat: 9-12
Confirmation Number: 70-30642/NY1
Order Summary: $755.00
)
loop, parse, var, `n,`r
    str .= trim(RegExReplace(A_LoopField, "m).*:\S?(.*)$","$1")) "`n"
sendinput,  % str
ExitApp