Sign in to follow this  
Followers 0
Wb-FreeKill

How to search for a word in html/txt file?

10 posts in this topic

I want to make a search "engine" for a html/txt file. Is it possible to search for a specific word in the file?

Share this post


Link to post
Share on other sites

May help

$sFileName = '';Filename here
$sWord = '';Se the word here

$sText = FileRead($sFilename,FileGetSize($sfilename))
MsgBox(0,'',StringInStr($sText,$sWord))

Share this post


Link to post
Share on other sites

#Include <GUIConstants.au3>


$sFileName = 'dansk-engelsk.html'
$sWord = 'aftenandagt'

$sText = FileRead($sFilename,FileGetSize($sfilename))
MsgBox(0,'',StringInStr($sText,$sWord))

it gives me the error o in the msgbox, is it because it cant find the file, or the word in the .html file?

for eksample, i want it so search for a word in the .html document, and then show it on the msgbox, if it finds it!

Share this post


Link to post
Share on other sites

Maybe a caps problem?

#Include <GUIConstants.au3>
$sFileName = 'dansk-engelsk.html'
$sWord = 'aftenandagt'

$sText = FileRead($sFilename,FileGetSize($sFileName))   <------------
MsgBox(0,'',StringInStr($sText,$sWord))

Share this post


Link to post
Share on other sites

what you mean?

Share this post


Link to post
Share on other sites

I just tested:

$sFileName = 'c:\boot.ini';Filename here
$sWord = 'part';Se the word here

$sText = FileRead($sFilename,FileGetSize($sfilename))
MsgBox(0,'',StringInStr($sText,$sWord))

And it worked. Can you show a little more?

Share this post


Link to post
Share on other sites

There is not more :idiot:

When i run your script, i get "59" why that?

Share this post


Link to post
Share on other sites

There is not more :idiot:

When i run your script, i get "59" why that?

<{POST_SNAPBACK}>

I adjusted the code a little.

$sFileName = 'c:\boot.ini';Filename here
$sWord = 'part';Se the word here

$sText = FileRead($sFilename,FileGetSize($sfilename))
If StringInStr($sText,$sWord) Then MsgBox(0,'', "Word is found in file!")

Share this post


Link to post
Share on other sites

O, okay.. i tried to make a GUI aout of it, but it doesn't seem to work

#include <GUIConstants.au3>

global $sText

GUICreate("Dictionary search", 300, 225)
GUISetState(@SW_SHOW)

$search = GUIctrlcreateinput("input search word",10,30, 150, 25)

$button = GUICtrlCreateButton("Start Search", 10, 60, 70, 20)








while 1

       $msg = GUIGetMsg()
       if $msg = $GUI_EVENT_CLOSE then
       exitloop
       endif
      
       if $msg = $button then
       

       $sFileName = 'c:\fil.htm'
       $sWord = '(GUIread)$search'

       $sText = FileRead($sFilename,FileGetSize($sfilename))
       If StringInStr($sText,$sWord) Then MsgBox(0,'', "Word is found in file!")
       endif      
      
       If $sText = -1 Then
       MsgBox(0, "Error", "Unable to open file.")
       endif


wend

Can i get it to write the line were it found the word?

thx for your help

Share this post


Link to post
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
Sign in to follow this  
Followers 0