jjump Posted September 8, 2008 Posted September 8, 2008 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
Andreik Posted September 8, 2008 Posted September 8, 2008 (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 September 8, 2008 by Andreik
jjump Posted September 8, 2008 Author Posted September 8, 2008 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
Andreik Posted September 8, 2008 Posted September 8, 2008 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])
jjump Posted September 8, 2008 Author Posted September 8, 2008 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
Andreik Posted September 8, 2008 Posted September 8, 2008 (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 September 8, 2008 by Andreik
jjump Posted September 8, 2008 Author Posted September 8, 2008 (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? CODEAutoItSetOption ("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 September 8, 2008 by jjump
ptrex Posted September 8, 2008 Posted September 8, 2008 @all MAybe this can get you going. ConsoleWrite(__StringFindOccurances("This Test the Whole Test World","Test World") & @CRLF) Func __StringFindOccurances($sStr1, $sStr2) Return UBound(StringSplit($sStr1, $sStr2, 1)) - 2 EndFunc regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now