Jump to content

Recommended Posts

Posted

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,

Posted (edited)

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
  • Moderators
Posted

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.

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...