我使用HttpWebRequest传递URL,然后需要保存HttpWebResponse返回的html。返回的响应有很多\ r \ n,\ n和\ t,并且所有“=”(等于)都附加了反斜杠。我需要删除它们,以便返回的tml是干净的并且可以直接使用。
使用的代码是:
HttpWebRequest request = WebRequest.Create("http://noirimdev02:8080/cps/rde/xchg/rimvenezuela/hs.xsl/1351.htm?xsl=pearl_series_landingpage.xsl&catid=0651C91110FA48BEBFD7C05413185395&pid=F6794FC1CB244538BB592A47505062BC&count=2") as HttpWebRequest;
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Read the whole contents and return as a string
result = reader.ReadToEnd();
}
result = result.Replace("\n", " ");
result = result.Replace("\r", " ");
result = result.Replace("\t", " ");
Console.WriteLine(result);
Console.ReadLine();
Nimish
答案 0 :(得分:1)
看起来好像你已经处理过\ n,\ r和\ t的情况,如果我理解正确的话,留下等号后面的尾部'\'来解决?您可以使用与其他方法相同的方法来实现这一目标:
result = result.Replace(@"=\", "=");
或者,如果你想同时处理所有案件:
result = Regex.Replace(result, "[\n\r\t]|=\\\\", delegate(Match match)
{
return match.Value == @"=\" ? "=" : " ";
});