Jump to content

Recommended Posts

Posted

Is there any way to get the total count of characters in a txt file, or maybe make a GUI that will count every character typed (or pasted) into it? I post a lot of tutorials and links into websites and this would be really useful for me. I just need ideas on how to go about it, I could probably write it myself.

Posted

Probably a silly idea but here goes.

Read file

Strip carraige returns

use StringSplit with space as the delimiter then Array[0] should contain amount of words.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Posted

HI,

may be a beginning.

$var = FileOpenDialog("TextFile", "C:\", "Txt-files (*.txt)", 1 );+ 4 )

If @error Then
    MsgBox(4096,"","No File(s) chosen")
Else
    $var = StringReplace($var, "|", @CRLF)
    MsgBox(4096,"","You chose " & $var)
EndIf

$count = 0

For $i = Asc('a') To Asc('z')
    $CharCount = _CountChars($var, Chr($i), 1)
    If $CharCount Then
        $count = $count + 1
        ConsoleWrite($count & '.' & @TAB &  '[' & Chr($i) & '] ' & $CharCount &  @LF)
    EndIf
Next

For $x = Asc('A') To Asc('Z')
    $CharCount = _CountChars($var, Chr($x), 1)
    If $CharCount Then
        $count = $count + 1
        ConsoleWrite($count & '.' & @TAB &  '[' & Chr($x) & '] ' & $CharCount &  @LF)
    EndIf
Next    

For $x = Asc('0') To Asc('9')
    $CharCount = _CountChars($var, Chr($x), 1)
    If $CharCount Then
        $count = $count + 1
        ConsoleWrite($count & '.' & @TAB &  '[' & Chr($x) & '] ' & $CharCount &  @LF)
    EndIf
Next    

Func _CountChars($h_File, $v_Char, $i_CaseSensitive = 0); 1 = Case Sensitive
    If Not FileExists($h_File) Then
        SetError(1)
        Return 0
    EndIf
    
    If $i_CaseSensitive = 0 Then
        $a_Split = StringSplit(StringLower(FileRead($h_File, FileGetSize($h_File))), $v_Char)       
    ElseIf $i_CaseSensitive = 1 Then
        $a_Split = StringSplit(FileRead($h_File, FileGetSize($h_File)), $v_Char)
    Else
        SetError(2)
        Return 0
    EndIf
    Return UBound($a_Split) - 2
EndFunc

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Posted (edited)

$file = FileOpen(@DesktopDir & "\Muzen.txt", 0)
$string = FileRead($file)
MsgBox(0, $string, $string)
$num = 0
For $i = 32 To 255
    StringReplace($string, Chr($i), "")
    $num = $num + @extended
Next
MsgBox(0, $num, $num)

Edit: lol could be so simple...

:D

Edited by marfdaman

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • Moderators
Posted

filegetsize( "bla.txt" )

Ding Ding Ding!! lol...

$StringLen = StringLen(FileRead('results.txt'))
$FileSize = FileGetSize('results.txt')

MsgBox(64, 'info', $StringLen & @CR & $FileSize)

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.

Posted
$file = FileOpen(@DesktopDir & "\Muzen.txt", 0)
$string = FileRead($file)
MsgBox(0, $string, $string)
$num = 0
For $i = 32 To 255
    StringReplace($string, Chr($i), "")
    $num = $num + @extended
Next
MsgBox(0, $num, $num)oÝ÷ ØGb¶Z%r¥u·¬¢È¦¦Wþ«¨µå¨ÂØZKz··öËaz¢"fy«­¢+Ø¥¹±Õ±ÐíÕ¥
½¹ÍѹÑ̹ÔÌÐì()Õ¥
ÉÑ ÅÕ½Ðí
¡É
½Õ¹ÐÅÕ½Ðì°ÌÀÀ°ÈÀÀ°´Ä°´Ä°    ¥Ñ=H ÀÌØí]M}=YI1AA]%9=°ÀÌØí]M}
1%AM%   1%9L¤¤((ÀÌØí¥Ñ|ÄôÕ¥
Ñɱ
ÉѥРÅÕ½Ðí%¹ÁÕÐQáÐ!ɸÅÕ½Ðì°À°ÈÀ°ÌÀÀ°ÄàÀ¤(ÀÌØí1±|ÈôÕ¥
Ñɱ
ÉÑ1° ÅÕ½ÐíQ½Ñ°
¡ÉÌèÅÕ½Ðì°À°À°ØÀ°ÈÀ¤(ÀÌØí1±|ÌôÕ¥
Ñɱ
ÉÑ1° ÅÕ½Ðí¹ÕµÈÅÕ½Ðì°ÜÀ°À°ÄÈÀ°ÈÀ¤(ÀÌØí ÕÑѽ¹|ÐôÕ¥
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐíMÕµ¥ÐÅÕ½Ðì°ÈÀÀ°À°ÄÀÀ°ÈÀ¤)Õ¥MÑMÑÑ ¤)]¡¥±Ä($ÀÌØíµÍôÕ¥Ñ5Í ¤(%M±Ð($%
ÍÀÌØíµÍôÀÌØí    ÕÑѽ¹|Ð($$$íøÀÌØí¥±ô¥±=Á¸¡Í­Ñ½Á¥ÈµÀìÅÕ½ÐìÀäÈí5Õ鸹ÑáÐÅÕ½Ðì°À¤($$$ÀÌØíÍÑÉ¥¹ôÕ¥
ÑɱI ÀÌØí¥Ñ|Ĥ($$$íø5Í    ½à À°ÀÌØíÍÑÉ¥¹°ÀÌØíÍÑÉ¥¹¤($$$ÀÌØí¹Õ´ôÀ($$%½ÈÀÌØí¤ôÌÈQ¼ÈÔÔ($$%MÑÉ¥¹IÁ± ÀÌØíÍÑÉ¥¹°
¡È ÀÌØí¤¤°ÅÕ½ÐìÅÕ½Ðì¤($$$ÀÌØí¹Õ´ôÀÌØí¹Õ´¬áѹ($$%9áÐ($$%Õ¥
ÑɱMÑÑ ÀÌØí1±|̰ÀÌØí¹Õ´¤(%
ÍÀÌØíµÍôÀÌØíU%}Y9Q}
1=M($%á¥Ñ1½½À(%
ͱÍ(%¹M±Ð)]¹)á¥
Posted (edited)

Hi,

did you test it? IMO it doesn't work because it counts letters twice. Hugo = 8

But if that is what you wanted, ... :D

So long,

Mega

For me this works as I expected:

#include <GuiConstants.au3>

GUICreate("CharCount", 300, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Edit_1 = GUICtrlCreateEdit("Input Text Here.", 0, 20, 300, 180)
$Label_2 = GUICtrlCreateLabel("Total Chars: ", 0, 0, 60, 20)
$Label_3 = GUICtrlCreateLabel("number", 70, 0, 120, 20)
$Button_4 = GUICtrlCreateButton("Submit", 200, 0, 100, 20)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Button_4
;~ $file = FileOpen(@DesktopDir & "\Muzen.txt", 0)
            $string = GUICtrlRead($Edit_1)
            Local $array = StringSplit($string, "")
            
            $num = 0
            For $i = 1 To UBound($array) - 1
                If StringIsAlNum($array[$i]) Then
                    $num += 1
                EndIf
            Next
            GUICtrlSetData($Label_3, $num)
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

  • Moderators
Posted

I agree with th.meger here... that doesn't make much sense...

$StringLen = StringLen(FileRead('results.txt'))
$FileSize = FileGetSize('results.txt')
$StringSplit = StringSplit(FileRead('results.txt'), '')
MsgBox(64, 'info', $StringLen & @CR & $FileSize & @CR & UBound($StringSplit) - 1)
Here are some different ways that all came out the same result.

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.

Posted

I agree with th.meger here... that doesn't make much sense...

Thanks for supporting me this time. :D

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Posted

HI,

I can put 30,000 chars into it. :D

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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
×
×
  • Create New...