国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 編程設計 > 正文

如何做一個文本搜索?

2020-06-19 13:42:00
字體:
來源:轉載
供稿:網友

<%
head = "
搜索"
SearchString = Request("SearchString")
count=0

Function UnMapPath( Path )
    UnMapPath = Replace(Mid(Path, Len(Server.MapPath("/")) + 1), "/", "/")

' 把當前目錄的實際路徑轉換為虛擬路徑.
End Function


Function SearchFile( f, s, title )
  Set fo = fs.OpenTextFile(f)
  content = fo.ReadAll

' 把全部文本讀到content.
  fo.Close
  SearchFile = InStr(1, content, S, vbTextCompare) > 0

' 從第一個字符開始檢查content里面是否有S.
  If SearchFile Then

' 如果有,則提出文件title存入變量.
      pos1 = InStr(1, content, "<title>", vbTextCompare)
      pos2 = InStr(1, content, "</title>", vbTextCompare)
      title = ""
      If pos1 > 0 And pos2 > 0 Then

' title標記中間的字符.
        title = Mid( content, pos1 + 7, pos2 - pos1 - 7 )
      End If
  End If
End Function

Function FileLink( f, title )
  vPath = UnMapPath( f.Path )

' 獲取路徑.
  If title = "" Then title = f.Name

' 做個鏈接.
  FileLink = "<A HREF=""" &  vPath & """>" & title & "</A>"
  FileLink = "<UL>
?" & FileLink & "</UL>"
End Function

Sub SearchFolder( fd, s )
  found = False 
  For each f In fd.Files
      pos = InStrRev(f.Path, "." )
      If pos > 0 Then
        ext = Mid(f.Path, pos + 1 )
      Else
        ext = ""
      End If
      If LCase(ext) = "htm" Then

' 顯示擴展名字為HTM的文件.
        If SearchFile( f, s, title ) Then
            Response.Write FileLink(f, title)
            count=count+1
            Response.Write cstr(count)
        End If
      End If
  Next

  For each sfd In fd.SubFolders
      SearchFolder sfd, s
  Next
End Sub
%>
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title><%=head%></title>
</head>

<body>

<h1>
星河影動之無敵文本搜索<%=head%></h1>

<hr>

<form action="search.asp" method="Get">
    <p>
請輸入想要搜索的內容: <input type="text"
    size="20" name="SearchString" value="<%=SearchString%>"> <input
    type="submit" value="
搜索"> </p>
</form>
<%
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set fd = fs.GetFolder( Server.MapPath("/") ) 

' 設置開始搜索的路徑.

If SearchString <> "" Then
  Response.Write "<H2>
搜索<font color=red>" & SearchString & "</font>結果如下:</H2><P>"
  SearchFolder fd,SearchString
End If
%>
<hr>
</body></html>

[1]

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 韩城市| 田林县| 枞阳县| 华亭县| 天津市| 兴山县| 浏阳市| 探索| 突泉县| 济源市| 临泽县| 蓬莱市| 蒙阴县| 房山区| 方山县| 伊春市| 上栗县| 松原市| 桃园市| 麻城市| 农安县| 石家庄市| 东宁县| 彝良县| 扶沟县| 平度市| 松江区| 射洪县| 阿克苏市| 元氏县| 霍城县| 安龙县| 泰和县| 武乡县| 大埔区| 乌海市| 兰西县| 北票市| 从化市| 温宿县| 望城县|