Jump to content

What would I put here?


Fewmitz
 Share

Recommended Posts

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

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

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 by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

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 by picaxe
Link to comment
Share on other sites

  • Moderators

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...