Print Page | Close Window

Search File for String Value

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1854
Printed Date: 29 March 2026 at 8:42am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Search File for String Value
Posted By: jwartman
Subject: Search File for String Value
Date 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.



Replies:
Posted By: Coco Brown
Date 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 .



Posted By: jwartman
Date 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
%>




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net