Hi all,
the script I'm writing needs to count the number of matching "strings" in clipboard.
so how do I search the contents of the clipboard and return the number of matches for a string eg number of times "green rabbit" appears in the clipboard.
Thanks
Count matching string from clipboard
Moderators: Dorian (MJT support), JRL
There are probably other ways but I would simply get the clipboard text and then use Separate> to get a count. The "count" variable provided by Separate> will be one greater than the number of instances.
Code: Select all
GetClipBoard>strText
Separate>strText,green rabbit,item
Sub>item_count,1
MDL>%item_count% "green rabbit" found
Hi Danton and JRL,
The above will count all occurrances of "green rabbit" but will miss:
Green rabbit
GREEN RABBIT
...etc
If you want to count them all no matter what case was used, you could modify JRL's code like this:
Another way to do this would be as follows:
Used as it is, the above will be case in-sensitive but you can use the other pattern if you actually want a case-sensitive match.
Another benefit to this method is... if you are doing a case-insensitive match and you'd like to see the actual strings you matched, they will be stored in variables MATCHES_1, MATCHES_2, etc. whereas they are not stored using the Separate> method.
Take care
The above will count all occurrances of "green rabbit" but will miss:
Green rabbit
GREEN RABBIT
...etc
If you want to count them all no matter what case was used, you could modify JRL's code like this:
Code: Select all
GetClipBoard>strText
LowerCase>strText,lower_strText
Separate>lower_strText,green rabbit,item
Sub>item_count,1
MDL>%item_count% "green rabbit" found
Code: Select all
GetClipBoard>strText
//Case In-Sensitive match
Let>pattern=green rabbit
//Case Sensitive match
//Let>pattern=(?-i)green rabbit
RegEx>pattern,strText,0,matches,num,0
MDL>%num% "%pattern%" found
Another benefit to this method is... if you are doing a case-insensitive match and you'd like to see the actual strings you matched, they will be stored in variables MATCHES_1, MATCHES_2, etc. whereas they are not stored using the Separate> method.
Take care
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -