Sign in to follow this  
Followers 0
jjump

Need to make a script count how many times a word appears

8 posts in this topic

Hi,

I need to make a script count how many times a word appears in a document before it gets to a certain word... Is this possible?

Ian

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

Hi,

I need to make a script count how many times a word appears in a document before it gets to a certain word... Is this possible?

Ian

Try this:

#include <File.au3>
$PATH = FileOpenDialog("SELECT",@ScriptDir,"All (*.*)",1)
$WORD = InputBox("WORD","TYPE HERE A WORD")
$COUNT = 0
$FILE = FileOpen($PATH,0)
For $INDEX = 1 To _FileCountLines($PATH)
    $LINE = FileReadLine($FILE,$INDEX)
    $SPLIT = StringSplit($LINE," ")
    If $SPLIT[0] <> 0 Then
        For $FIND = 1 To $SPLIT[0]
            If $WORD = $SPLIT[$FIND] Then $COUNT += 1
        Next
    EndIf
Next
FileClose($FILE)
MsgBox(0,"COUNT",$COUNT)
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Hi,

Thank you for your reply. If I wanted to just search for a single word and not want to choose the word, would I just write:

$WORD = "My Word"

Also, if I wanted to not open a file, but just wanted the script to search an open windows, would I just write

$DATA = WinActivate("MY OPEN WINDOW")

Many Thanks

Ian

Share this post


Link to post
Share on other sites

Hi,

Thank you for your reply. If I wanted to just search for a single word and not want to choose the word, would I just write:

$WORD = "My Word"

Also, if I wanted to not open a file, but just wanted the script to search an open windows, would I just write

$DATA = WinActivate("MY OPEN WINDOW")

Many Thanks

Ian

If you want all windows with a certain word in title:

AutoItSetOption ("WinTitleMatchMode",2)
$WIN = WinList("Your word","")
MsgBox(0,"COUNT",$WIN[0][0])

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Hi,

Thank you once again for your reply. So if I wanted to search for a word in a certain open window, how would I write that?

Many Thanks

Ian

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi,

Thank you once again for your reply. So if I wanted to search for a word in a certain open window, how would I write that?

Many Thanks

Ian

I don't understand very well what you want but if you want to search for a word in a ceratin open window( in some control) you must get data from window.

$DATA = WinGetText("TEST - Notepad","")
$COUNT = 0
$WORD = "Your word"
$SPLIT = StringSplit($DATA,@CRLF)
If $SPLIT[0] <> 0 Then
    For $INDEX = 1 To $SPLIT[0]
        $LINE = StringSplit($SPLIT[$INDEX]," ")
        If $LINE <> 0 Then
            For $FIND = 1 To $LINE[0]
                If $WORD = $LINE[$FIND] Then $COUNT += 1
            Next
        EndIf
    Next
EndIf
MsgBox(0,"COUNT",$COUNT)
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I tested this, but it still shows a count of 0, even when there are some in the window.. What am I doing wrong?

CODE
AutoItSetOption ("WinTitleMatchMode",2)

$DATA = WinGetText("Source","")

Sleep(2000)

$COUNT = 0

$WORD = "stock"

$SPLIT = StringSplit($DATA,@CRLF)

If $SPLIT[0] <> 0 Then

For $INDEX = 1 To $SPLIT[0]

$LINE = StringSplit($SPLIT[$INDEX]," ")

If $LINE <> 0 Then

For $FIND = 1 To $LINE[0]

If $WORD = $LINE[$FIND] Then $COUNT += 1

Next

EndIf

Next

EndIf

MsgBox(0,"COUNT",$COUNT)

Many Thanks

Ian

Edited by jjump

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0