title: How can I search for a string in a txt file?
body: <p>Is there some way that I can search in a <code>example.txt</code> file for a string <code>example</code>? </p>
  
  <p>I tried <code>Fileread</code> and <code>Fileseek</code> but it is not working yet... later I'd like to write to the file, that's why I use <code>FileOpen</code> with the <code>a</code> append attribute:</p>
  
  <pre><code>FileOpen $4 "$SYSDIR\drivers\etc\hosts" a
  FileSeek $4 0 SET
  FileRead $4 $1
  ${If} $1 != "example"
  Strcmp $1 "example" end 0
  </code></pre>
  
  <p>Or can I walk through the file with <code>While</code>? But when does the file end?</p>
  
  <h2>Update</h2>
  
  <pre><code>!define IP_AND_DISPATCHER "30.0.0.0 dispatcher"
      FileOpen $0 "$SYSDIR\drivers\etc\hosts" a
  loop:
  
     FileRead $0 $2
     IfErrors done
     Messagebox MB_OK "$2"
        StrCmp $2 "${IP_AND_DISPATCHER}$\r$\n" 0 loop
  MessageBox MB_OK "$${IP_AND_DISPATCHER} found"
  FileClose $2     ;close file
  Quit
  
  done:
      FileSeek $0 0 END
      FileWrite $0 "$\r$\n" ; new line
      FileWrite $0 "${IP_AND_DISPATCHER}" ;write ip and dispatcher
      FileWrite $0 "$\r$\n" ; extra line
   FileClose $0     ;close file
  </code></pre>
  
  <p>Now its working, but is there a way to not write the <code>30.0.0.0 dispatcher</code> so not the entire line... just, for example, the <code>dispatcher</code> word?</p>