John117 Posted October 24, 2008 Share Posted October 24, 2008 (edited) hey guys, I need to pull a code from a couple thousand emails I have. The code replaces where you see 'X' in the below example. The location of the code is unknown as far as character length is concerned. The following code worked for another project I had, So I am hoping this one will as well. Please help if you can . . . #include <file.au3> #include <IE.au3> #include <Array.au3> HotKeySet("{ESC}", "_Quit") HotKeySet("{NUMPAD1}", "_Run1") $oIE = _IEAttach ("The Email With The Code") $sHTML = _IEBodyReadHTML ($oIE) While 1 Sleep(50) WEnd Func _Run1() ;CODE: XXXXX-XXXXX-XXXXX-XXXXX-XXXXX Behold ;This is the string I am looking to pull only the XXX-XXX stuff from. It includes code at the start of it and space and behold at the end. $aNameArray = StringRegExp($sHTML, " ([[:alnum:]]*?)\-([[:alnum:]]*?)X", 3) ;This code worked with a similar project with a unknown email address ;$aNameArray = StringRegExp($sHTML, "CODE: ([[:alnum:]]*?) Behold", 0) ;I tried this adaptation MsgBox(4096, "Working", $aNameArray[0]) ;MsgBox(4096, "Working", $sHTML) EndFunc ;==>Run Func _Quit() Exit EndFunc ;==>Quit Edited October 24, 2008 by Hatcheda Link to comment Share on other sites More sharing options...
Varian Posted October 24, 2008 Share Posted October 24, 2008 Have you tried _StringBetween()? Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 24, 2008 Share Posted October 24, 2008 How about the expression "CODE: ([0-9\-]+?) Behold". See if that returns the code. Link to comment Share on other sites More sharing options...
John117 Posted October 24, 2008 Author Share Posted October 24, 2008 from the example, is that not by position? - that is unknown and changes. - the example I included is the best method as a catch all, but I am not sure how to correctly adapt it for the new string . . . Link to comment Share on other sites More sharing options...
John117 Posted October 24, 2008 Author Share Posted October 24, 2008 How about the expression "CODE: ([0-9\-]+?) Behold". See if that returns the code. so try this? $aNameArray = StringRegExp($sHTML, "CODE: ([0-9\-]+?) Behold", 3) or $aNameArray = StringRegExp($sHTML, "CODE: ([0-9\-]+?) Behold", 0) Link to comment Share on other sites More sharing options...
John117 Posted October 24, 2008 Author Share Posted October 24, 2008 ok, as written does not work. . . #include <file.au3> #include <IE.au3> #include <Array.au3> HotKeySet("{ESC}", "_Quit") HotKeySet("{NUMPAD1}", "_Run1") $oIE = _IEAttach ("The Website") $sHTML = _IEBodyReadHTML ($oIE) While 1 Sleep(50) WEnd Func _Run1() ;CODE: XXXXX-XXXXX-XXXXX-XXXXX-XXXXX Behold ;$aNameArray = StringRegExp($sHTML, " ([[:alnum:]]*?)\-([[:alnum:]]*?)X", 3) ;This code worked with a similar project with a unknown email address $aNameArray = StringRegExp($sHTML, "CODE: ([0-9\-]+?) Behold", 0) ;$aNameArray = StringRegExp($sHTML, "CODE: ([[:alnum:]]*?) Behold", 0) ;I tried this adaptation MsgBox(4096, "Working", $aNameArray) ;MsgBox(4096, "Working", $sHTML) EndFunc ;==>Run ;_FileWriteToLine($sFile, $iLine, $sText[, $fOverWrite = 0]) Func _Quit() Exit EndFunc ;==>Quit _StringBetween() Link to comment Share on other sites More sharing options...
Varian Posted October 24, 2008 Share Posted October 24, 2008 (edited) I was thinking something like this: Func _Run1() $aNameArray = _StringBetween($sHTML, 'CODE:', 'Behold');Finds all occurences of "CODE: [i]SomeString [/i]Behold" If not IsArray($aNameArray) Then Return For $i=0 to ubound($aNameArray) -1 $ReplacementString = 'CODE: Behold' ;Whatever your Static string to place is If StringInStr($sHTML, $aNameArray[$i]) Then StringReplace($sHTML, $aNameArray[$i], $ReplacementString) Next EndFunc This should work if you are either removing the XXX stuff or replacing it with the same string each time Edited October 24, 2008 by Varian Link to comment Share on other sites More sharing options...
John117 Posted October 24, 2008 Author Share Posted October 24, 2008 (edited) ok, I can get it to show the first two now, but not three $aNameArray = StringRegExp($sHTML, "CODE: ([[:alnum:]]*?)\-([[:alnum:]]*?)-", 3) MsgBox(4096, "Working", $aNameArray[0] & "-" & $aNameArray[1]) Edit: Checking previous post . . . . Edited October 24, 2008 by Hatcheda Link to comment Share on other sites More sharing options...
John117 Posted October 24, 2008 Author Share Posted October 24, 2008 :-) ok, that works! added #String to the top $aNameArray = _StringBetween($sHTML, 'CODE:', 'Behold');Finds all occurences of "CODE: SomeString Behold" Link to comment Share on other sites More sharing options...
Varian Posted October 24, 2008 Share Posted October 24, 2008 Yeah, I forgot to mention the includes! 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