Jump to content

return full line from part text?


 Share

Recommended Posts

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

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

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 by bluerein
Link to comment
Share on other sites

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 by SoulA
Link to comment
Share on other sites

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

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?

Link to comment
Share on other sites

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 by bluerein
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...