|
|
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>
|
|
|
|
|
|
|
|