efficient way to find string with streamreader

前端 未结 3 1585
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 10:57

I get web response and use streamreader to obtain the response as a string

my code is

HttpWebResponse response = (HttpWebResponse) request.GetRespons         


        
3条回答
  •  遥遥无期
    2021-01-12 11:36

    Well, personally I would use:

    string line;
    
    while ((line = reader.ReadLine()) != null)
    {
        if (line.Contains(...))
        {
        }
    }
    

    Reading the line gives you the data and tells you whether you've reached the end of the stream. I agree with Jeff though - "parsing" HTML by reading it line by line is generally a bad idea. It may be good enough in your specific situation, of course.

提交回复
热议问题