ASP.NET(vb.net) & Search and Highlight Text file - The in this tutorial, you’ll learn and example scripts how to Search and Highlight Text file using by ASP.NET scripts.
ShotDev Focus:
- ASP.NET(vb.net) & Search and Highlight Text file
Example
AspNetSearchTextFile2.aspx
<%@ Import Namespace="System.IO"%> <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Dim StrWer As StreamReader Dim StrBui As StringBuilder Dim strLine As String Dim SearchText As String = "2008" Dim intLine As Integer Dim strNum As String StrWer = File.OpenText(Server.MapPath("MyFiles/") & "shotdev.txt") StrBui = New StringBuilder() Do Until StrWer.EndOfStream intLine = intLine + 1 strLine = StrWer.ReadLine() If InStr(strLine, SearchText) > 0 Then strLine = Replace(strLine, SearchText, _ "<span style=""background-color:red;"">" & SearchText & "</span>") strNum = strNum & intLine & "," End If StrBui.AppendLine(strLine & "<br>") Loop Me.lblText1.Text = StrBui.ToString() Me.lblText2.Text = "Found Line : " &strNum.ToString StrBui = Nothing StrWer.Close() End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText1" runat="server"></asp:Label><br /> <asp:Label id="lblText2" runat="server"></asp:Label><br /> </form> </body> </html>
Screenshot
1fascinating…
…