Kyler Carlson Posted December 5, 2006 Share Posted December 5, 2006 okay basically, i want to keep track of how many times that my different friends say "lol" in a chat program. I can do everything except for pick the word out of the chat screen. Say that $text is all of the text in the conversation and that this is the conversation. User1 [10:17 P.M.]: hah yes i'm doing fine lol User2 [10:18 P.M.]: thats good User1 [10:18 P.M.]: ya it is User2 [10:18 P.M.]: lol User1 [10:18 P.M.]: lol how dould i pull from that that user one has said "lol 2 times and that user2 has said "lol 1 time? I can do the rest but this part is really confusing me. Thanks for any help Link to comment Share on other sites More sharing options...
darkshadow791 Posted December 5, 2006 Share Posted December 5, 2006 If all of the text is in a single variable try using StringInStr() Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
Valuater Posted December 5, 2006 Share Posted December 5, 2006 just playing Dim $text[6], $display $text[1] = "User1 [10:17 P.M.]: hah yes i'm doing fine lol" $text[2] = "User2 [10:18 P.M.]: thats good" $text[3] = "User1 [10:18 P.M.]: ya it is" $text[4] = "User2 [10:18 P.M.]: lol" $text[5] = "User1 [10:18 P.M.]: lol" $User_Name = StringSplit("User1,User2", ",") Dim $User_Count[UBound($User_Name)+ 1] $find = "lol" for $x = 1 to UBound($User_Name) -1 for $i = 1 to UBound($text) -1 If StringInStr($text[$i], $User_Name[$x]) And StringInStr($text[$i], $find) Then $User_Count[$x] = $User_Count[$x] + 1 Next $display = $display & $User_Name[$x] & " #" & $User_Count[$x] & @CRLF Next MsgBox(64, "User and lol count", $display) 8) Link to comment Share on other sites More sharing options...
florisch Posted December 5, 2006 Share Posted December 5, 2006 Yes, like the above example. I would sugest some changes: 1. If you have all the text in one variable (eg $chat), you can make the $text-array with stringsplit($chat, @CRLF) 2. In case you want to count lols of all users, instead of the given subset $User_Names, just use on string to gather the usernames and count them afterwards. My solution would look like this: Dim $count = "" Dim $result = "" Dim $chat ; chat contains all the chat text $chat = "User1 [10:17 P.M.]: hah yes i'm doing fine lol " & @CRLF & "User2 [10:18 P.M.]: lol" & @CRLF & "User1 [10:18 P.M.]: lol" $lines = stringsplit($chat, @CRLF, 1) ; split the chat into lines for $i = 1 to $lines[0] if StringInStr($lines[$i], "lol") then $username = stringsplit($Lines[$i]," ") ; username should be the first word in the line $count = $count & $username[1] & " " endif next ; for counting we use a little trick, stringreplace gives the number of replacements in @extended do $username = stringsplit($count," ") $count = stringreplace($count, $username[1],"") $result = $result & $username[1] & " said lol " & @extended & " times." & @CRLF $count = StringStripWS($count,7) until $username[0] = 1 msgbox(0,"Result", $result) One flaw remains: if a user writes more than one line at once, this will fail. Link to comment Share on other sites More sharing options...
NeoFoX Posted December 5, 2006 Share Posted December 5, 2006 This will count al the lols for each user in a .txt file... perhaps usefull for logging chat progs #include <file.au3> $file = "test.txt" $lines = _FileCountLines($file) $display = "" $User_Name = StringSplit("User1,User2", ",") Dim $User_Count[UBound($User_Name)+ 1] $find = "lol" for $x = 1 to UBound($User_Name) -1 for $i = 1 to $lines If StringInStr(FileReadLine($file,$i), $User_Name[$x]) And StringInStr(FileReadLine($file,$i), $find) Then $User_Count[$x] = $User_Count[$x] + 1 Next $display = $display & $User_Name[$x] & " #" & $User_Count[$x] & @CRLF Next MsgBox(64, "User and lol count", $display) Neo [center][font="Arial"]--- The Neo and Only --- [/font][font="Arial"]--Projects---[/font]Image to Text converterText to ASCII converter[/center] Link to comment Share on other sites More sharing options...
JSThePatriot Posted December 5, 2006 Share Posted December 5, 2006 I would assume that you are wanting to do this without having to manually input the username of so many friends.Now I have a few questions, and then we will get into regular expressions which is how this will need to be done to get the proper output.Are you going to be in a chat room where there will be multiple users allowed?How are you obtaining the chat conversation?Log File?AutoIt?Other?Are you willing to do a lot of strenuous testing in order to make this work?Answer the questions to my satisfaction, and I will be more than happy to help you work up a Regular Expression that will allow you to do as you please. StringRegExp is the Function name in case you want to look it up and do a bit of research yourself.I hope this gets us on the way,JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008Â Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
/dev/null Posted December 5, 2006 Share Posted December 5, 2006 (edited) how dould i pull from that that user one has said "lol 2 times and that user2 has said "lol 1 time? I can do the rest but this part is really confusing me. Thanks for any help Try this. ATTENTION: You will need the attached hash.au3 in your include folder, as the one posted (see link in code) has some problems with line continuation "_". #include <Hash.au3> #cs Link to Hash UDF: http://www.autoitscript.com/forum/index.php?showtopic=11611 #ce Dim $text[7], $display $text[1] = "User1 [10:17 P.M.]: hah yes i'm doing fine lol lol" $text[2] = "User2 [10:18 P.M.]: thats good" $text[3] = "User1 [10:18 P.M.]: ya it is" $text[4] = "User2 [10:18 P.M.]: lol" $text[5] = "User3 [10:18 P.M.]: nope" $text[6] = "User1 [10:18 P.M.]: lol" $user_quotes = _HashF_NewInstance() For $i = 1 to UBound($text)-1 $temp = StringSplit($text[$i]," ") $user = $temp[1] $temp = StringReplace($text[$i],"lol","-del-",0,0) $new_lol = @extended $old_lol = _HashF_Get($user,$user_quotes) _HashF_Put($user, $old_lol + $new_lol, $user_quotes) Next _HashF_SortKeysAsc($user_quotes) $users = _HashF_Keys($user_quotes) For $i = 1 To $users[0] ConsoleWrite("User: " & $users[$i] & " Nr. of lol: " & _HashF_Get($users[$i],$user_quotes) & @CRLF) Next Cheers KurtHash.au3 Edited December 5, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Kyler Carlson Posted December 5, 2006 Author Share Posted December 5, 2006 (edited) okay thanks for all of the responese, they are all doing atleast some of what i want them to. To answer JS's questions, I'm getting the text my recording the window text (wingettext) but this really isn't the best way i know because it could have false positives if i was looking at a webpage or something. I am willing to do some testing but not a huge amount. I would really love it if it was possible to get the usernames aoutmatically because, yes, i will be in chat rooms with multiple people chatting at once. Back on the subject of how to obtain the text in the chat room. I'm using AIM and i haven't managed to get any of the control read functions to work. does anyone else have an idea how to do this or an alternative to getting the text of the entire window? thanks for all of the help already guys btw. Edited December 5, 2006 by Kyler Carlson Link to comment Share on other sites More sharing options...
JSThePatriot Posted December 6, 2006 Share Posted December 6, 2006 okay thanks for all of the responese, they are all doing atleast some of what i want them to. To answer JS's questions, I'm getting the text my recording the window text (wingettext) but this really isn't the best way i know because it could have false positives if i was looking at a webpage or something. I am willing to do some testing but not a huge amount. I would really love it if it was possible to get the usernames aoutmatically because, yes, i will be in chat rooms with multiple people chatting at once. Back on the subject of how to obtain the text in the chat room. I'm using AIM and i haven't managed to get any of the control read functions to work. does anyone else have an idea how to do this or an alternative to getting the text of the entire window? thanks for all of the help already guys btw.I appreciate your response to my questions. Unfortunately regular expressions take a bit of testing to be sure it is right. (At least in my meager experience).If you are using AIM chat rooms, I will see what I can do. That I can test a bit on my own.Also using StringInStr() per line to see if it has lol in it, would be a good way to decide if you need that line. Then you could split the string on the : if that is indeed a splitting character.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008Â Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
Kyler Carlson Posted December 7, 2006 Author Share Posted December 7, 2006 (edited) Sleep(5000) Dim $count = "" Dim $result = "" Dim $chat $text = WinGetText("") $lines = StringSplit($text,@LF) for $i = 1 to $lines[0] if StringInStr($lines[$i], "lol") then $lol = 0 For $times = 1 to 100 $string = StringInStr($lines[$i] ,"lol",0, $times) If $string <> 0 Then $lol = $lol + 1 EndIf Next $username = stringsplit($Lines[$i]," ") If $username[1] = "" Then $username[1] = $username[2] Do If $lol > 0 Then $count = $count & $username[1] & " " $lol = $lol - 1 Until $lol = 0 endif next do $username = stringsplit($count," ") $count = stringreplace($count, $username[1],"") If @extended <> "" Then $result = $result & $username[1] & " said lol " & @extended & " times." & @CRLF $count = StringStripWS($count,7) until $username[0] = 1 msgbox(0,"Result", $result) okay, this is what i'm using now. Its basically based off of florisch's code with some bug fixes and support for multiple "lol"'s in a line. Thanks guys and sry if i made you angry at all /dev/null, I was just verrryy confused about why that mine wasn't working when others were. I knew i was doing something wrong but wasn't sure and yes i had been testing them... understanding them was an issue however which is why i kept asking for help. anyway, thatsk again everybody for all of your help. Edited December 7, 2006 by Kyler Carlson Link to comment Share on other sites More sharing options...
/dev/null Posted December 7, 2006 Share Posted December 7, 2006 (edited) okay... i've gotten something up and working for one person as far as i can tell but i'm still not sure how to make this code work for multiple people. If anyone can modify this, thanks a lot!aren't there enough examples of working solutions in this thread??? Did you bother to test and understand any of them?CheersKurt Edited December 7, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now