 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
edu
Joined: 12 Oct 2006 Posts: 98 Location: Canada
|
Posted: Thu May 24, 2007 5:48 pm Post subject: clipboard word count, possible? |
|
|
Hello,
I wonder if it's possible to make a simple clipboard word count with AutoHotKey.
This is the farthest I got, just for testing purposes:
| Code: | Loop, parse, clipboard, %A_Space%,
{
MsgBox, %A_Index%
}
return |
I guess I would get it if I could retrieve what is the number of the last loop, that is, the last %A_Index%.
Any suggestion?
Eduardo |
|
| Back to top |
|
 |
ggirf14
Joined: 01 Nov 2005 Posts: 96 Location: Ottawa
|
Posted: Thu May 24, 2007 6:24 pm Post subject: |
|
|
Try this:
| Code: | Loop, parse, clipboard, %A_Space%,
{
;MsgBox, %A_Index%
Totalwords = %A_Index%
}
MsgBox, %Totalwords% |
|
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6921 Location: Pacific Northwest, US
|
Posted: Thu May 24, 2007 6:24 pm Post subject: |
|
|
| Code: |
StringSplit, count, Clipboard, %A_space%`n, `r
msgbox, %count0%
|
This also takes into account carriage returns _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5438 Location: /b/
|
Posted: Thu May 24, 2007 7:05 pm Post subject: |
|
|
A parsing loop outperforms StringSplit, so I'd use ggirf14's method. It can also be done with RegEx, so if you're interested:
| Code: | RegExReplace(clipboard, "\b.+?\b", "", count)
count := Ceil(count / 2)
MsgBox, There are %count% words in the clipboard. |
_________________
 |
|
| Back to top |
|
 |
edu
Joined: 12 Oct 2006 Posts: 98 Location: Canada
|
Posted: Fri May 25, 2007 12:37 am Post subject: |
|
|
Wow! Thank you fellow users!
I found the script from ggirf14 more accurate.
Titan, I didn't know that a regexmatch could be converted into a number, or am I missing something?
Edu |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6921 Location: Pacific Northwest, US
|
Posted: Fri May 25, 2007 1:13 am Post subject: |
|
|
| Manual - RegExReplace wrote: |
OutputVarCount
The unquoted name of a variable in which to store the number of replacements that occurred (0 if none).
|
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
YMP
Joined: 23 Dec 2006 Posts: 299 Location: Russia
|
Posted: Fri May 25, 2007 6:21 am Post subject: |
|
|
| edu wrote: | | I found the script from ggirf14 more accurate. |
However I doubt it's accurate enough because it depends on the number of spaces between words. It also reports words to be on the clipboard when there are only spaces there. The same applies to engunneer's example.
Titan's code is the best, though it must depend on what is considered to be word and non-word characters, in which, as far as I know, AutoHotkey is currently fully reliable only for English texts. So a word having a national character in the middle will probably be taken for two words.
Perhaps this variation may be more 'international':
| Code: |
RegExReplace(Clipboard, "\S(?:\s|$)", "", Count)
Msgbox, % Count
|
|
|
| Back to top |
|
 |
BoBoĻ Guest
|
Posted: Fri May 25, 2007 8:29 am Post subject: |
|
|
StringReplace?
| Quote: | | When the last parameter is UseErrorLevel, ErrorLevel is given the number occurrences replaced (0 if none). Otherwise, ErrorLevel is set to 1 if SearchText is not found within InputVar, or 0 if it is found. |
| Code: | StringReplace, OutputVar, ClipBoard, Autohotkey, , UseErrorLevel
MsgBox, The word 'Autohotkey' occurs %ErrorLevel% times within the text. |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|