Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find and copying text...

Been working with qm for a little bit and have caught on with some parts of it...

Trying to automate an item.

I have some data which I'd like to extract that will begin and end with a certain set of characters such ==Info== The start and end of each of these seperators will be encased with a date stamp and a username. It will be inbetween plenty of data seperated with the same date stamp and username.

It may be like this:

01/01/2010 00:10 (A1A):
Text I'd like
01/01/2010 00:00 (A1A):

The text is expected to be different between this markers each time the macro runs.

I suspect I'd be looking to use a regular expression (pattern) of sorts? but not sure how I would extract that text for later use?

Do I need to figure out some logic to copy everything around it and delete what I don't want (maybe in a notepad window) or can the macro do it all?

What I may then to do to catch errors if the pattern isn't found is prompt the user to highlight the required text then click resume to pick up from a new point to get it copied.

Would I need to use the (pattern) item?

Any help appreciated.
Maybe I over complicated it and would match the pattern, then working from the next line use foreach through the lines with an if to break it when the pattern is matched again?

I could then cycle through those lines to paste into the other window?
Macro Macro1496
Copy      Help
str s=
;01/01/2010 00:10 (A1A):
;Text I'd like
;01/01/2010 00:00 (A1A):
;Text I'd like 2
;Text I'd like 2
;02/01/2010 02:00 (A2B):
;Text I'd like 3
;Text I'd like 3
;Text I'd like 3

ARRAY(str) a
if(!findrx(s "^(\d\d/\d\d/\d{4} \d\d:\d\d) \(.+?\):[]==Info==[](?s)(.+?)[]==Info==" 0 4|8 a)) end "failed. Either s is empty, or the format changed."

int i
for i 0 a.len
,out "<><color ''0xff0000''>%s</color>[]<color ''0x8000''>%s</color>" a[1 i] a[2 i]

Thanks for the quick reply.

As text could be different all the time can this be targeted to just find the first instance of ==Info== from the top (currently getwintext, though I it will be a textbox control when I get it working) and grab the text inbetween? Maybe I'd need to find and cut blocks?

I've tried toying around but I think I am removing items that I need but don't quite understand yet. Its the findrx syntax is troubling me.

Macro Macro1118
Copy      Help
str s.getwintext(id(15 "Notepad"))

str r
if(findrx(s "^(\d\d/\d\d/\d{4} \d\d:\d\d) \(.+?\):[]==Info==[](?s)(.+?)[]==Info==" 0 8 r 2)<0) end "failed. Either s is empty, or the format changed."

out r

Thought I would revive this following a progression of the original question Smile

I am looking to find a set of text and assign aspects of the block to different strings (if possible). I need the text after the colon and space.

** Start**
Name: The General
Date: 15/06/2011 19:18:05
Title: Find and copying text...
Code: Random
Message: Possible multi

** End**

The above would be inbetween plenty other text and there could be multiple but I only need the first (from top)

Can I drop all this to the clipboard or do I need to place text into a notepad window and find/replace etc?
I figured putting the Message at the bottom might make it easier to pull the multi line text as it can terminate at ** End **
Macro Macro1526
Copy      Help
str s=
;** Start**
;Name: The General
;Date: 15/06/2011 19:18:05
;Title: Find and copying text...
;Code: Random
;Message: Possible multi
;** End**

ARRAY(str) a
str rx=
;\*\* Start\*\*
;Name: (.*)
;Date: (.*)
;Title: (.*)
;Code: (.*)
;Message: (?s)(.*)
;\*\* End\*\*

if(findrx(s rx 0 1|8 a)<0) out "not found"; ret

out a[1]
out a[2]
out a[3]
out a[4]
out a[5]
Fantastic! Easier than it was my head.

How do you make it only find the first and ignore any others that exist in the text?
This finds only the first.

Forum Jump:

Users browsing this thread: 1 Guest(s)