codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Text Search  Cooler King at 15:41 on Thursday, February 26, 2004
 

Hi all,

I want to able to search through a text file and display the lines if they have a match. I've got it to work with the following code below only matches exactly what search for, if i search for say "Bloggs" it matches it but if i search for "Bloggs Marketing" it doesn't match because the actual line in the text file looks like this:

"Joe Bloggs Department of Marketing"

So heres my question how do i get it to search the whole string and return unexact matches (e.g. "Bloggs Marketing")

Thanks in advance.

Heres my code:

<% option explicit %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Telephone Directory - Results Page</title>
<link href="domcompat.css" rel="stylesheet" type="text/css">
</head>

<body>
<div align="center">
<form>
<div>
<table>
<tr class="pdcellcolour2">
<td colspan="2"><img src="directorytitle.jpg"></td>
</tr>
<tr class="pdcellcolour2">
<td>
<br><strong>Search Results for <%=Request ("SearchField")%></strong><br><br>

<%

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.fileSystemObject")

Dim strSearchField
strSearchField = Request("SearchField")

Dim objTextStream
Dim strFileContents
Dim objLine
Dim strLine
Dim strMatch
const strFileName = "e:\htdocs\Directory\directory.txt"
const fsoForReading = 1


Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)


Function printLine(strLine)
response.write strLine & "<br>"
end Function

While Not objTextStream.AtEndOfStream
objLine = objTextStream.ReadLine
if instr(objLine,uCase(strSearchField)) > 0 Then
printLine(objLine)
End if
WEnd


objTextStream.Close
Set objTextStream = Nothing

Set objFSO = Nothing
%>
<br><br></td>
</tr>
</table>
</div>
</form>
</body>
</html>









Useful Links



CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
• Run a program both on windows and linux
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2
• Petrel.V2013.2
• Altair.HyperWorks.v12
• VoluMill.v6.1
• VoluMill.NEXION.6
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2014