Word Count
Word Count
Is there an easy way to count words in a string? In Arexx I believe it was something like:
words("some string here")
words("some string here")
You could use this to count whitespace characters :
Code: Select all
Procedure.l CountChars(a.s,s.s)
!MOV edi,dword[esp] ;pointer to the first character in string (first function parameter)
;firstly we must found the lenght of the string:
!CLD ;clear DF (Direction Flag). Could be not necessary.
!XOR al,al ;set NULL character in AL register
!XOR ebx,ebx ;init counter
!MOV ecx,ebx ;lets set 4294967295 ($FFFFFFFF) characters maximum
!DEC ecx
!REPNZ scasb ;repeat comparing AL CPU register content with [edi]
!JECXZ go ;if NULL byte is not found within those 4294967295 characters then exit giving 0
!NOT ecx ;else, some adjusts. Now we have the lenght at ecx register
!MOV edi,dword[esp] ;point again to the first character in string (first function parameter)
!MOV eax,dword[esp+4]
!MOV al,byte[eax] ;al=character to find
!@@:REPNZ scasb ;repeat comparing AL CPU register content with [edi]
!JECXZ go ;until ecx value is reached
!INC ebx ;or a match is found
!JMP @r ;continue comparing next character
!go:MOV eax,ebx ;output the matches counter
ProcedureReturn
EndProcedure-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
-
sec
- Enthusiast

- Posts: 792
- Joined: Sat Aug 09, 2003 3:13 am
- Location: 90-61-92 // EU or ASIA
- Contact:
Code: Select all
s.s="abc def a re era " ;s(len(s)) must equal = " " space
i = 0
count = 0
Repeat
i=FindString(s," ",i+1)
If i>0
count=count+1
EndIf
Until i=0
Debug count
To search the forums:
(1) Click the Search link at the top-right of this window.
(2) Type in your keyword(s) and click the Search button.
viewtopic.php?t=3603&highlight=countwords
(1) Click the Search link at the top-right of this window.
(2) Type in your keyword(s) and click the Search button.
viewtopic.php?t=3603&highlight=countwords
No offence, but this has the worst search page ever. I've been on a lot of forums, yet whatever I do this brings a lot of results. Mostly rubbish.wayne1 wrote:To search the forums:
(1) Click the Search link at the top-right of this window.
(2) Type in your keyword(s) and click the Search button.![]()
viewtopic.php?t=3603&highlight=countwords
No offense, but you haven't used a lot of forum software - have you? PHPbb's searching is pretty darn good as far as forum searches go ...
Last edited by Karbon on Sun Oct 12, 2003 4:35 pm, edited 1 time in total.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
In a test I found that in larger strings (50bytes+...) FindString is much slower than a loop with: if PeekB(i) = ' ': wordcount+1:endifsec wrote:![]()
Code: Select all
s.s="abc def a re era " ;s(len(s)) must equal = " " space i = 0 count = 0 Repeat i=FindString(s," ",i+1) If i>0 count=count+1 EndIf Until i=0 Debug count
Because FindString does not remember it's last call, it always has too start from the string's beginning.
../tomio
I was only joking and modified that post right after you replied!
Seriously, PHPbb's searching isn't that bad.
Click search, select "Search for all terms" type in "count words"
Bam - the "Challenge: Fastest Way To Parse And Count Words?" thread comes up. Don't know what more you could ask for
It's not perfect, but the random free-form input of a forum isn't really the easiest thing to do context searching on...
Seriously, PHPbb's searching isn't that bad.
Click search, select "Search for all terms" type in "count words"
Bam - the "Challenge: Fastest Way To Parse And Count Words?" thread comes up. Don't know what more you could ask for
It's not perfect, but the random free-form input of a forum isn't really the easiest thing to do context searching on...
Last edited by Karbon on Sun Oct 12, 2003 4:39 pm, edited 2 times in total.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
If you don't use the Option 'Search for ANY terms...' you get a better result when searching. Maybe this is of interest: viewtopic.php?t=2450&highlight=count+words
Here's a little trick I learned for counting characters:
Eric
Code: Select all
s.s="abc def a re era "
NoSpaces.s = RemoveString(s, " ")
Debug Len(s) - Len(NoSpaces)A built in CountChars() would be good - that way you could count the number of any character you wanted in a string..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net


