我正在为一个简单的行解析一个 html 文件。所以我没有使用第 3 方库,只是使用普通的字符串函数(s.subString() 等)。
我的问题 是我无法在 HTML 中正确找到特定元素,因为它们包含制表符、结束符、回车符。
如何打印以下字符串以将所有回车符显示为\r,将所有尾行显示为\n & 等。 这样我就可以准确地看到 HTML 文件的布局并确保我的
.subString("<div class=\"x\">")
没有失败,因为文本确实是
("<div \t\r\nclass=\"x\">"
还是什么?
我的代码:
WebClient wc = new WebClient();
string html = wc.DownloadString(String.Format("http://www.ipchecking.com/?ip={0}&check=Lookup", ip));
Console.Write( html ); // I want to print in the raw form where \r characters are actually shown as \r characters
请您参考如下方法:
html = html.Replace("\r", "\\r").Replace("\n","\\n").Replace("\t","\\t");
