bluerein Posted October 13, 2008 Share Posted October 13, 2008 Im trying to get a line from just part of its text and struggling finding anything.. example I have a index.html and I need to search it for the text "@import" which is ok ,but I need to return the full line its on... Any ideas regards m-tek Link to comment Share on other sites More sharing options...
dbzfanatic Posted October 13, 2008 Share Posted October 13, 2008 FileReadLine() and StringInStr() should work. Just return the line if it meets the requirements. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Marlo Posted October 13, 2008 Share Posted October 13, 2008 Maybe this will help Func _SearchString() $File = FileOpen("yourfile.html") $Dat = FileRead($File) $Lines = StringSplit($Dat, @CR) For $I = 1 To $Lines[0] If StringInStr($Lines[$I], "@IMPORT") Then Return $Lines[$I] ExitLoop EndIf Next EndFunc Click here for the best AutoIt help possible.Currently Working on: Autoit RAT Link to comment Share on other sites More sharing options...
SoulA Posted October 13, 2008 Share Posted October 13, 2008 Wondering if you can do something like this? #include <file.au3> Dim $aRecords _FileReadToArray("index.html",$aRecords) For $i = 1 to $aRecords[0] If StringInStr($aRecords[$i], "@import") Then MsgBox(0,"found it", $aRecords[$i]) ;print the line that it was found on and all the text ExitLoop EndIf Next Link to comment Share on other sites More sharing options...
bluerein Posted October 13, 2008 Author Share Posted October 13, 2008 wow thanks for the help !! Both work but return the required line plus 2 up and 2 down ...so its returning 5 lines ANy ideas?? Link to comment Share on other sites More sharing options...
Marlo Posted October 13, 2008 Share Posted October 13, 2008 then you must have @IMPORT on those 5 lines : / Click here for the best AutoIt help possible.Currently Working on: Autoit RAT Link to comment Share on other sites More sharing options...
bluerein Posted October 13, 2008 Author Share Posted October 13, 2008 no it doesnt ... my file looks like this sometext @import sometext and thats what it returns now if I edit the file like so sometext 1111 @import 1111 sometext filling in the gaps ..it returns correctly!! hmmmmm Link to comment Share on other sites More sharing options...
dbzfanatic Posted October 13, 2008 Share Posted October 13, 2008 Try StringStripWS() Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
SoulA Posted October 13, 2008 Share Posted October 13, 2008 Try StringStripWS()Or add another If statement... If $aRecords[$i] <> "" Then... whatever for my code. Link to comment Share on other sites More sharing options...
bluerein Posted October 13, 2008 Author Share Posted October 13, 2008 (edited) no its not the gaps !! I just used URLDownloadToFile to get the file then #include <file.au3> Dim $aRecords _FileReadToArray("index.html",$aRecords) For $i = 1 to $aRecords[0] If StringInStr($aRecords[$i], "@import") Then MsgBox(0,"found it", $aRecords[$i]);print the line that it was found on and all the text ExitLoop EndIf Next to get the line if I download the file first then open it then save it , it works but if I dont open it then save it returns wrong... how strange try this see if you get the same as me #include <IE.au3> #include <INet.au3> #include <file.au3> global $site="http://www.invisionmodding.com/index.php" global $site1="http://www.autoitscript.com/forum/index.php" URLDownloadToFile ($site,"index.html") URLDownloadToFile ($site1,"index1.html") Dim $aRecords _FileReadToArray("index.html",$aRecords) For $i = 1 to $aRecords[0] If StringInStr($aRecords[$i], "@import") Then MsgBox(0,"found it", $aRecords[$i]);print the line that it was found on and all the text _FileReadToArray("index1.html",$aRecords) For $i = 1 to $aRecords[0] If StringInStr($aRecords[$i], "@import") Then MsgBox(0,"found it", $aRecords[$i]);print the line that it was found on and all the text ExitLoop EndIf Next ExitLoop EndIf Next Edited October 13, 2008 by bluerein Link to comment Share on other sites More sharing options...
SoulA Posted October 14, 2008 Share Posted October 14, 2008 (edited) I got the same... the one index has a few LF's so they show up on new lines but the array doesn't split them up. You can do this to get rid of that. This should put it all on one line. #include <file.au3> Dim $aRecords _FileReadToArray("index.html",$aRecords) For $i = 1 to $aRecords[0] If StringInStr($aRecords[$i], "@import") Then MsgBox(0,"found it", StringReplace($aRecords[$i],@LF,""));print the line that it was found on and all the text ExitLoop EndIf Next Edited October 14, 2008 by SoulA Link to comment Share on other sites More sharing options...
SoulA Posted October 14, 2008 Share Posted October 14, 2008 could also do this.... not sure what you are looking for. #include <file.au3> Dim $aRecords _FileReadToArray("index.html",$aRecords) For $i = 1 to $aRecords[0] If StringInStr($aRecords[$i], "@import") Then $sString = StringTrimLeft($aRecords[$i], StringInStr($aRecords[$i], @LF, 0, 2)) $sString = StringTrimRight($sString, StringLen($sString) - StringInStr($sString, @LF)) MsgBox(0,"found it", $sString);print the line that it was found on and all the text ExitLoop EndIf Next Link to comment Share on other sites More sharing options...
Szhlopp Posted October 14, 2008 Share Posted October 14, 2008 Hey blue, I'm not quite sure what you want... The position? The full line text? Use this pattern for SRE: .*@import.* Flag: 3 Want the position of any of the full lines? StringInStr($String, $aSRE[0])oÝ÷ Øú,بÚ*¶+¶Æ®¶se7G&ætå7G"b33cµ7G&ærÂgV÷C´×÷'BgV÷C²ÂÂ" ^^^ Finds the second occurrance That help? RegEx/RegExRep Tester!Nerd Olympics - Community App!Login UDFMemory UDF - "Game.exe+753EC" - CE pointer to AU3Password Manager W/ SourceDataFiler - Include files in your au3!--- Was I helpful? Click the little green '+' Link to comment Share on other sites More sharing options...
bluerein Posted October 14, 2008 Author Share Posted October 14, 2008 (edited) Just to clear up Im just trying to get the whole line that has "@import" on it but for some reason #include <file.au3> Dim $aRecords _FileReadToArray("index.html",$aRecords) For $i = 1 to $aRecords[0] If StringInStr($aRecords[$i], "@import") Then $sString = StringTrimLeft($aRecords[$i], StringInStr($aRecords[$i], @LF, 0, 2)) $sString = StringTrimRight($sString, StringLen($sString) - StringInStr($sString, @LF)) MsgBox(0,"found it", $sString);print the line that it was found on and all the text ExitLoop EndIf Next that returns one blank now and one correct..... EDIT!!! managed to get it to work ....Its a bit scrappy but none the less works so thanks everyone for your help Edited October 14, 2008 by bluerein 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