【发布时间】:2013-01-28 16:48:58
【问题描述】:
我正在尝试从 webResposne 仅记录第 3 行(如果无法仅记录一行,则为第 1 到 3 行)。
这是我现在使用的代码的 sn-p。
StreamReader read = new StreamReader(myHttpWebResponse.GetResponseStream(), System.Text.Encoding.UTF8);
String result = read.ReadToEnd();
Log("Access", Server.HtmlEncode(result), "Success");
我得到以下输出
<html>
<head>
<title>Access is Granted.</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
...
等等。
我只想记录“(title>Access is Granted.(/title>”而不打印任何其他内容(或该行之后的任何内容)。
我该怎么做呢?
谢谢
【问题讨论】:
-
您是否尝试过为您的任务编写正则表达式?如果是这样,你有问题吗?
-
假设这个问题是“StreamReader.ReadLine 方法的名称是什么,如果可以调用它 3 次忽略结果前 2 次” - 可能重复 How to skip first line while reading csv using streamreader -
-
您确定只需要第 3 行还是您要专门处理的
标签?