Fewmitz Posted October 27, 2007 Share Posted October 27, 2007 Okay, so so far I have this code: #include <File.au3> $skooba = InputBox("What file", "Enter the whole file path here") $character = InputBox("What character","Enter the character to search for (search for a space for word count") _readfile($skooba, $character) Func _readfile($file) $fileh = FileOpen($file, 0 ) $number = 0 $x = 1 $y = _FileCountLines( $file ) For $avar = $x to $y Next FileClose( $fileh ) msgBox(0,"Character",$number) EndFunc What I'm trying to do is count the number of a certain character in a document, but as you can see, the For Statement is blank, and I have no idea what to put. Anyone have any ideas? Link to comment Share on other sites More sharing options...
Generator Posted October 27, 2007 Share Posted October 27, 2007 Maybe this is what you want? #include <File.au3> $skooba = InputBox("What file", "Enter the whole file path here") $character = InputBox("What character", "Enter the character to search for (search for a space for word count") _readfile($skooba, $character) Func _readfile($file, $char) $Count = 0 $Fileh = FileOpen($file, 0) For $i = 0 To _FileCountLines($Fileh) If StringInStr(FileReadLine($Fileh, $i), $char) Then $Count += 1 EndIf Next MsgBox(64, "Result", $Count & " matches.") $Count = 0 EndFunc ;==>_readfile Link to comment Share on other sites More sharing options...
Blue_Drache Posted October 27, 2007 Share Posted October 27, 2007 (edited) This is how I'd do it: (UNTESTED CODE) #include <File.au3> $f_File = InputBox("What file", "Enter the whole file path here") $str_Char = InputBox("What character", "Enter the character to search for (search for a space for word count") $var = _readfile($f_File, $str_Char) MsgBox(0, "", $var) Func _readfile($file) Local $fileh = FileOpen($file, 0), $intCount = 0, $intLoop, $intLoop2, $fTEMP, $intLines $intLines = _FileCountLines($file) For $intLoop = 1 To $intLines $fTEMP = StringSplit(FileReadLine($file, $intLoop), "") For $intLoop2 = 1 To $fTEMP[0] If $fTEMP[$intLoop2] = $str_Char Then $intCount += 1 Next Next FileClose($fileh) Return $intCount EndFunc ;==>_readfile Or something similar...whatever would work. Edited October 27, 2007 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
picaxe Posted October 28, 2007 Share Posted October 28, 2007 (edited) This works. The word count doesn't agree with GNU wc utility. However it seems to check out OK with wOuters excellent "StringRegExp Design GUI". #include <File.au3> $skooba = InputBox("What file", "Enter the whole file path here") $character = InputBox("What character", "Enter the character to search for (search for a space for word count") _readfile($skooba, $character) Func _readfile($file, $char) $Fileh = FileOpen($file, 0) $File_All = FileRead($Fileh) If $char <> "" Then ;If $char = " " Then $char = "\b[a-z]+\b" ; exclude numbers If $char = " " Then $char = "\b[a-z.0-9]+\b" ; include numbers $aMatch = StringRegExp($File_All, '(?i)' & $char, 3) MsgBox(64, "Result", UBound($aMatch) & " matches.") Else MsgBox(64, "Result", "A search character is required.") EndIf FileClose($Fileh) $aMatch = "" EndFunc Edited October 28, 2007 by picaxe Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 28, 2007 Moderators Share Posted October 28, 2007 Func _ReadFile($sFile, $sChars, $iCase = 0) StringReplace(FileRead($sFile), $sChars, "", $iCase) Return @extended EndFuncoÝ÷ ØêÚºÚ"µÍ[ÈÔXY[TJ ÌÍÜÑ[K ÌÍÜÐÚË ÌÍÚPØÙHH ][ÝÊÚJI][ÝÊBRY ÌÍÚPØÙH ÉÝÈ ][ÝÊÚJI][ÝÈ[ ÌÍÚPØÙHH ][ÝÉ][ÝÂÝ[ÔYÑ^XÙJ[TXY ÌÍÜÑ[JK ][ÝÊÜÊI][ÝÈ [È ÌÍÚPØÙH [È ][ÝÊ ][ÝÈ [È ÌÍÜÐÚÈ [È ][ÝÊI][ÝË ][ÝÉ][ÝË ÌÍÚPØÙJBT]^[Y[[ Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
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