Jump to content

Search for a specific term


Recommended Posts

How do you search for a specific term in a .txt file and then copy it to a seperate file.

For example if I wanted to search for "<img src=" in a html file and then write the results into a seperate file.

This?

Dim $Source = FileRead("c:\Test\test.html")
If @error Then
    MsgBox(16, "Error", "Unable to open file")
    Exit
EndIf

$Result = FileOpen(@ScriptDir & "\Out.txt", 1)

$str = StringRegExp($Source, '(?i)<img src=.*"', 3)

If Not IsArray($str) Then
    MsgBox(16, "Error", "Required string not found")
    Exit
EndIf

For $i = 0 To UBound($str) -1
    FileWriteLine($Result, $str[$i])
Next

FileClose($Source)
FileClose($Result)
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...