Search code examples
vb.netcontainswebresponse

vb.net find line that contain in a string


If I can find line that contains word in a file

File.ReadAllLines(html).FirstOrDefault(Function(x) x.Contains("something"))

How can I find all lines that contains in a string for example I made an webresponse

    Dim rt As String = "http://www.somesaite.com"
    Dim wRequest As WebRequest
    Dim WResponse As WebResponse
    Dim SR As StreamReader
    wRequest = FtpWebRequest.Create(rt)
    WResponse = wRequest.GetResponse
    SR = New StreamReader(WResponse.GetResponseStream)
    rt = SR.ReadToEnd

How to find lines that contains in rt ?


Solution

  • You could read all the text that the StreamReader gives you, and then you could split that by the Environment.NewLine character(s). Then you should just be able to use the lambda expression you first mentioned (as the File.ReadAllLines() method returns an array of strings).

    Dim FoundLine As String = SR.ReadToEnd().Split(Environment.NewLine).FirstOrDefault(Function(x) x.Contains("something"))