Jump to content
Sign in to follow this  
Zisly

Count a x word

Recommended Posts

Zisly

Well, I can't find anything which would count how many "x" words there is in a edit control..

Example: It will count how many "do" there is in the edit control..

If anyone knows how I could do this, please, post it!

Thanks in advance,

Zisly,

Share this post


Link to post
Share on other sites
Nahuel

First you should read the whole text in the edit control:

$text=GuiCtrlRead($edit)

Then use StringSplit() to create an array with all the words the edit control has using " " as a separator:

$words=StringSplit($text," ")

in a loop, check how many times a given word repeats.

$x=0
$myword="autoit"
For $i=0 to $words[0]
      if $words[$i]=$myword then $x+=1
next

Now $x has the number of times the word repeats in the text:

MsgBox(0,"","The word " & $myword & " is " & $x & " times in the text")

Note that I just wrote those lines and they might not work, but you get the idea.

Edited by Nahuel

Share this post


Link to post
Share on other sites
Zisly

Thanks for the fast reply!

Share this post


Link to post
Share on other sites
SmOke_N

First you should read the whole text in the edit control:

$text=GuiCtrlRead($edit)

Then use StringSplit() to create an array with all the words the edit control has using " " as a separator:

$words=StringSplit($text," ")

in a loop, check how many times a given word repeats.

$x=0
$myword="autoit"
For $i=0 to $words[0]
      if $words[$i]=$myword then $x+=1
next

Now $x has the number of times the word repeats in the text:

MsgBox(0,"","The word " & $myword & " is " & $x & " times in the text")

Note that I just wrote those lines and they might not work, but you get the idea.

Wouldn't this be much easier?

StringReplace($text, $myword, "")
MsgBox(64, "Info", "Number of times word is in string = " & @Extended)

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.

Share this post


Link to post
Share on other sites
Nahuel

Dear ol' smoke... I must admit I missed you.

Mr Zisly, do what the man says.

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  

×