locked
Search word in File RRS feed

  • Question

  • User1109811461 posted

    Hi all,

    i'm using this following code to find specific key word in my notepad but it did not work, i only can find the first keyword, second and third cannot..my keyword is structure in sequence as follows:

    test1

    test2

    test3

    For Each line As String In File.ReadLines("D:\String.txt")
    If line.Equals(Request.ServerVariables("QUERY_STRING")) Then
    Response.Redirect("testpage.aspx")
    Else

    End If
    Next line

     Thanks. need help.

    Saturday, February 3, 2018 3:13 AM

Answers

  • User475983607 posted

    i'm using this following code to find specific key word in my notepad but it did not work, i only can find the first keyword, second and third cannot..my keyword is structure in sequence as follows:

    The code is designed to redirect when the first string is found.  Try the following approach.  

    Dim count as Integer = 0
    For Each line As String In File.ReadLines("D:\String.txt")
    	If line.Equals(Request.ServerVariables("QUERY_STRING")) Then
    		count = count + 1
    	End If
    Next line
    
    If count > 0 Then
    	Response.Redirect("testpage.aspx")
    End If

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 3, 2018 12:31 PM

All replies

  • User475983607 posted

    i'm using this following code to find specific key word in my notepad but it did not work, i only can find the first keyword, second and third cannot..my keyword is structure in sequence as follows:

    The code is designed to redirect when the first string is found.  Try the following approach.  

    Dim count as Integer = 0
    For Each line As String In File.ReadLines("D:\String.txt")
    	If line.Equals(Request.ServerVariables("QUERY_STRING")) Then
    		count = count + 1
    	End If
    Next line
    
    If count > 0 Then
    	Response.Redirect("testpage.aspx")
    End If

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 3, 2018 12:31 PM
  • User1109811461 posted

    Hi  mgebhard

    Thanks you so much for your help. The code work for me.

    Thanks again.smile 

    Sunday, February 4, 2018 1:01 AM