私が考えることのできる最も速い方法は以下のとおりです。それはここでいくつかのダニを剃ることができないと言っているわけではありません...我々はこれ以上合理化できるかどうかを確認する他のフィードバックのために満足しています。
// WebClient is very bulky with a lot of stuff we don't need.
// By dealing with the request, response and stream ourself we can get the string a bit faster.
WebRequest request = WebRequest.Create("http://www.UrlToDownloadStringFrom.com");
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(stream);
// the result should return "firstWord~:::~secondWord" as expected.
string result = streamReader.ReadToEnd();
// split the string apart whenever the string ~:::~ appears within it.
string[] resultSplit = result.Split(new string[] { "~:::~" }, StringSplitOptions.None);
// resultSplit[0] is firstWord, resultSplit[1] is second word
string secondWord = resultSplit[1];
あなたはスピードをしたい場合、あなたは間違いなく、おそらくあなたが一度にいくつかのデータをダウンロードすることができます正規表現 –
を使用したくないでしょうか?新しい行が見つかるまでそれを読んでから、その行を好きなように処理するメソッドがあるとします。テキストが見つからなかった場合は、次の新しい行が見つかるまで、数バイトをさらにダウンロードしてください。 –
@VisualVincentそれは良い点ですが、テキストが1ギグファイルの最下部にあるとすれば、どれくらいの時間がかかりますか? – Dgameman1