Sign in to follow this  
Followers 0
gamepin126

Character count

14 posts in this topic

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.

Share this post


Link to post
Share on other sites



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.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#4 ·  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!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

filegetsize( "bla.txt" )


My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites

filegetsize( "bla.txt" )

that's the way i always do it... like to read in an entire text file you do:

$contents = FileRead("C:\blah.txt",FileGetSize("C:\blah.txt"))

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

filegetsize( "bla.txt" )

Ding Ding Ding!! lol...

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

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

[center]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.[/center]

Share this post


Link to post
Share on other sites
$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±Ð)]¹)á¥

Share this post


Link to post
Share on other sites

#9 ·  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

Share this post


Link to post
Share on other sites

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.


[center]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.[/center]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Thanks guys.

Share this post


Link to post
Share on other sites

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

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