Get number of occurrences to clipboard?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Get number of occurrences to clipboard?

Post by terrypin »

How would I find the number of times
</Placemark>
occurs and get that automatically onto the clipboard (for further processing elsewhere) please?

I can do the first stage, albeit in kludgy fashion, by using Find, then Mark All, then Edit > Copy Other > Bookmarked lines, but I've so far not found a way to copy the resulting number of lines in that final text doc. Using View > Document Properties displays the number, but short of an unreliable OCR tool I can't access it programmatically.

Terry, East Grinstead, UK
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You can find the number of lines in a document or a selection with:

Search | Replace... (<F8>):
Find what: .*\n
Replace with: \i\n

[X] Regular expression

Replace All
The last line of the result will contain the number of lines. But note that the number of lines you have copied and pasted is the number of lines containing occurrences of </Placemark>, not the number of occurrences of </Placemark>

You can get part of the way to finding the number of occurrences of </Placemark> in your original file with:

Search | Replace... (<F8>):
Find what: [\s\S]*?</Placemark>|[\s\S]+
Replace with: \i\n

[X] Regular expression

Replace All
The penultimate line of the result will contain the number of occurrences of </Placemark>.

Note to Helios: This solution could be improved if sequence numbers could be generated within replacement conditional expressions, but it seems they can't.
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Post by terrypin »

Many thanks, that's very clever! Added to my archives for future use.

I've actually just finished a macro (written with Macro Express Pro) that achieves it in a way that I understand more intuitively.
- Source is the KML file of an entire folder of Google Earth placemarks
- I place it into a variable
- Determine its length nBefore
- Delete all occurrences of the target, </Placemark>
- Determine the new length and hence the difference nDiff
- Divide nDiff by 12 (the target length) to get the count
Post Reply