efficient way to find string with streamreader

前端 未结 3 1589
佛祖请我去吃肉
佛祖请我去吃肉 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:38

    This really depends - do you need to know where in the DOM your particular text resides? How large is the input? Will your string ever be split between two lines?

    If you are only concerned about the presence of the text and your input is small enough to reside in memory, I'd just read the entire thing in to memory. I'm not sure what the exact algorithm the CLR uses to do string matching, but some of the faster routines involve pre-processing both the query and the string to be searched, and having more information for the pre-processing could potentially yield a faster search.

    Of course, this all depends on CLR internals and your particular requirements - test, test, test.

    If you want to capture more information about your text and its relation to the surrounding document, I'd suggest looking at the HtmlAgility library for parsing your document.

提交回复
热议问题