killaz219 2 Posted January 2, 2007 (edited) I made this yesterday, because I needed it for a small project. I threw it together so it is a little messy. I hope somebody finds it useful Example #include <GuiConstants.au3> GuiCreate("WordCounter", 392, 316,-1, -1) $Edit_1 = GuiCtrlCreateEdit("", 10, 10, 370, 270) $Button_2 = GuiCtrlCreateButton("Count", 10, 280, 370, 30) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button_2 $woot = GUICtrlRead($Edit_1) MsgBox(0, "", WordCount($woot)) EndSelect WEnd Exit Func WordCount($text) Global $word = 0, $temp = 0 For $i = 1 To StringLen($text) If (Asc(StringMid($text, $i, 1))) < 33 Then Do $i = $i + 1 Until (Asc(StringMid($text, $i, 1))) >= 33 Or $i > StringLen($text) $word = $word + 1 Else If $word = 0 Then $word = 1 Endif EndIf Next Return $word EndFunc Edited January 2, 2007 by killaz219 1 Infiniterider reacted to this Share this post Link to post Share on other sites
SmOke_N 210 Posted January 2, 2007 (edited) You could simplify your WordCount() function a tad if all you are doing is looking for spaces. Func _WordCount($text) Return UBound(StringSplit(StringReplace($text, @CRLF, ' '), ' ')) - 1 EndFuncoÝ÷ ØGb´êæk&Þz÷§jëh×6Func _WordCount($text) Return UBound(StringRegExp($text, '(?s)(?i)(.*?)\s', 3)) EndFunc Edited January 2, 2007 by SmOke_N 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
killaz219 2 Posted January 2, 2007 (edited) You could simplify your WordCount() function a tad if all you are doing is looking for spaces. Func _WordCount($text) Return UBound(StringSplit(StringReplace($text, @CRLF, ' '), ' ')) - 1 EndFuncoÝ÷ ØGb´êæk&Þz÷§jëh×6Func _WordCount($text) Return UBound(StringRegExp($text, '(?s)(?i)(.*?)\s', 3)) EndFunc Yes but sometimes words aren't seperated by only spaces. this would look like one word: Hello you And your second example is messed up if there is more then one space hello you Edited January 2, 2007 by killaz219 Share this post Link to post Share on other sites
tmo 0 Posted January 2, 2007 (edited) $text = "Hi, these " & @CRLF & " are 19 words.Even if i forget that space after the dot the words are counted correctly" $array = StringRegExp($text, "[\s,;:\.]*([[:alnum:]]+)[\s,;:\.]*", 3) ConsoleWrite(UBound($array))oÝ÷ Ù§]ب©eÉ©e×Ü"Ûè"½éâØ^jºÚÊÊ-«r¢ç(ºWp®+^iû§rبƥçp¢·l¦Xjëh×6Func word_split($text) Return StringRegExp($text, "[\s,;:\.]*([[:alnum:]]+)[\s,;:\.]*", 3) EndFunc works fine so far Edited January 2, 2007 by tmo Share this post Link to post Share on other sites
killaz219 2 Posted January 2, 2007 $text = "Hi, these " & @CRLF & " are 19 words.Even if i forget that space after the dot the words are counted correctly" $array = StringRegExp($text, "[\s,;:\.]*([[:alnum:]]+)[\s,;:\.]*", 3) ConsoleWrite(UBound($array)) I like it. Much shorter then mine. 1 Infiniterider reacted to this Share this post Link to post Share on other sites
llamnuds 0 Posted January 3, 2007 A handy script. Cheers, llamnuds Share this post Link to post Share on other sites