leo11173 Posted June 6, 2010 Share Posted June 6, 2010 Hi, i am trying to transfert lines monitored from a chat to another chat using StringRegExp but i am kinda lost and did not manage to search what i was looking for.The main problem is that i would like to only catch the last line said from the chat by user "themessager". Actualy the code will report all the lines themessager publiched on the chat each time i execute the script.$Text=ControlGetText("[CLASS:ThunderRT6FormDC]","","[CLASSNN:RichTextWndClass4]") $Value=StringSplit($Text,@CRLF) For $i=1 To $Value[0] If StringRegExp($Value[$i],"themessager") Then controlSend("[CLASS:ThunderRT6FormDC]", "", "Edit1", $Value[$i]) EndIf NextThanks in advance. Link to comment Share on other sites More sharing options...
sahsanu Posted June 6, 2010 Share Posted June 6, 2010 The main problem is that i would like to only catch the last line said from the chat by user "themessager". Actualy the code will report all the lines themessager publiched on the chat each time i execute the script. Try starting from the end and if it matches the user name then exit loop. Take this as an example: $Text="[jim] Hi boy" & @CRLF & _ "[themessager] Hi" & @CRLF & _ "[themessager] How are you doing today?" & @CRLF & _ "[jim] I'm doing fine" & @CRLF & _ "[themessager] this is my last line" & @CRLF & _ "[jim] ok" $Value=StringSplit($Text,@CRLF) For $i=$Value[0] To 1 Step -1 If StringRegExp($Value[$i],"themessager") Then ;controlSend("[CLASS:ThunderRT6FormDC]", "", "Edit1", $Value[$i]) ConsoleWrite($Value[$i] & @LF) ExitLoop EndIf Next Cheers, sahsanu Link to comment Share on other sites More sharing options...
leo11173 Posted June 6, 2010 Author Share Posted June 6, 2010 Thanks sahsanu you solved my problem.here's the correct script now :It will get text of specified user (exemple user is named themessager there) from chat window then send the last line user posted to another window$Text=ControlGetText("[CLASS:ThunderRT6FormDC]","","[CLASSNN:RichTextWndClass5]") $Value=StringSplit($Text,@CRLF) For $i=$Value[0] To 1 Step -1 If StringRegExp($Value[$i],"themessager") Then ;Envoi des dialogues message dans le chat controlSend("[CLASS:ThunderRT6FormDC]", "", "Edit1", $Value[$i] & @CRLF) ExitLoop EndIf Next Link to comment Share on other sites More sharing options...
jchd Posted June 7, 2010 Share Posted June 7, 2010 There is much a simpler way using a single regexp (without duplicating then splitting data): Local $s = "abc hoigzho fhoijg def" & @CRLF & _ "fgh gzjpogerjkpo" & @CRLF & _ "abc jogrjpher xyz jfgzjo" & @CRLF & _ "def jiogrjohjpoh" & @CRLF & _ "uvw jpgejpher def jiofgd" & @CRLF & _ "def kopgrekpo" & @CRLF & _ "xyz jipgrejphe" & @CRLF Local $user = "def" Local $text = StringRegExp($s, "(*CRLF)(?ms)^" & $user & "([^\n]*)$(?!.*^" & $user & ")", 1) _ArrayDisplay($text, $user & " last said") If you want to keep user name at front of it's phrase, remove the perenthesis and use Local $text = StringRegExp($s, "(*CRLF)(?ms)^" & $user & "[^\n]*$(?!.*^" & $user & ")", 1) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
leo11173 Posted June 7, 2010 Author Share Posted June 7, 2010 @jchd I did not manage to execute your code exemple. Link to comment Share on other sites More sharing options...
Juvigy Posted June 7, 2010 Share Posted June 7, 2010 Put this in the beginning : #Include <Array.au3> Link to comment Share on other sites More sharing options...
jchd Posted June 7, 2010 Share Posted June 7, 2010 Sorry I forgot to mention the include. Many common includes get in automagically in my script testing template. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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