1

I am parsing a html file for one simple line. So I am not using a 3rd party library just normal string functions(s.subString() etc.).

My problem is I cannot correctly find specific elements in the HTML because they contain tab characters, endlines, carriage returns.

How can I print the following string to display all the carriage returns as \r, all endlines as \n & etc. So I can then see exactly the layout of the HTML file & ensure my

.subString("<div class=\"x\">") 

is not failing because the text is really

("<div \t\r\nclass=\"x\">" 

or something?

My code:

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
mmdemirbas
  • 9,060
  • 5
  • 45
  • 53
sazr
  • 24,984
  • 66
  • 194
  • 362
  • Use an HTML parser. The [HTML Agility Pack](http://htmlagilitypack.codeplex.com/) is popular. – Oded Mar 02 '12 at 11:26

2 Answers2

4
html = html.Replace("\r", "\\r").Replace("\n","\\n").Replace("\t","\\t");
mmdemirbas
  • 9,060
  • 5
  • 45
  • 53
0

I think the best way will be using regular expressions REGEX:

Sample Regular Expressions

mmdemirbas
  • 9,060
  • 5
  • 45
  • 53
Alex
  • 5,971
  • 11
  • 42
  • 80
  • first of all thank you, second i can read certian html tags after saving them in a string, why not? – Alex Mar 02 '12 at 11:38