How to remove \ r \ n \ t and extra \ appended for "=" from HttpWebResponse

I am using HttpWebRequest to pass url and then afterwards need to store the html returned by HttpWebResponse. The resulting answer has many \ r, \ n and \ t, and all "=" (equal) are appended with a backslash. I need to remove them so that the returned tml is clean and usable.

Used code:

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

+1


a source to share


1 answer


It looks like you've already handled the \ n, \ r and \ t cases, leaving the trailing '\' after the equal signs remain resolvable, if I understood correctly? You can do this using the same approach as others:

result = result.Replace(@"=\", "=");

      



Or, if you want to handle all cases at the same time:

result = Regex.Replace(result, "[\n\r\t]|=\\\\", delegate(Match match)
{
    return match.Value == @"=\" ? "=" : " ";
});

      

+1


a source







All Articles