Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Search File for String Value
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Search File for String Value

 Post Reply Post Reply
Author
jwartman View Drop Down
Newbie
Newbie


Joined: 15 April 2003
Location: United States
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote jwartman Quote  Post ReplyReply Direct Link To This Post Topic: Search File for String Value
    Posted: 16 April 2003 at 8:34am
Hi!!  Hopefully somebody out here can help this newbie out.  I'm trying to create a webpage that when the user clicks on a button it goes out and reads from a text file and searches for 10 different strings.  It then returns either a true or false if it found each string.  I then would like to display a certain image for each depending on if it returned a true or false value.  Any help would be GREATLY appreciated.
Back to Top
Coco Brown View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 April 2002
Location: United States
Status: Offline
Points: 245
Post Options Post Options   Thanks (0) Thanks(0)   Quote Coco Brown Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2003 at 12:13pm

Read in the text file into myTextFile.
get a string out of your form using request.form().  These are easy to get, and there are plenty tutorials on that.  The Command you want however, is INSTR.  It tells you at what position in a string does a part of a string start.  In this instance, if we recieve a position number back, one that is not 0, then this string piece is in the larger string.

if instr(myTextFile,aString) <> 0 then
   response.write aString & " was found"
else
   response.write aString & " was not found"
end if

I hope this helps .

Back to Top
jwartman View Drop Down
Newbie
Newbie


Joined: 15 April 2003
Location: United States
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote jwartman Quote  Post ReplyReply Direct Link To This Post Posted: 28 April 2003 at 6:46pm

Coce thanks for your reply!!  I was able to read in a file and search for a string.  Only thing is it returns a value as it searches throughout the entire file, so i get 100-200 statements saying found or not found.  How can I only return "one" value either yes the value was found(either 1 or 100 times) or no the value wasn't found.

Thanks to anyone who can help.  Sorry I'm still a rookie.

Below is the code:

<%
 Dim aString
 aString = "RDO0410"
    Set fs = CreateObject("Scripting.FileSystemObject")
    filename=server.mappath("/MyWeb/aobfsts.txt")
 Set readfile=fs.OpenTextFile(filename,1,False)
    Do until readfile.AtEndOfStream
        myTextFile=readfile.readline
  if instr(myTextFile,aString) <> 0 then
      response.write aString & " was found"
  else
      response.write aString & " was not found"
  end if
    Loop
    readfile.close
    set readfile=nothing
%>

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.