sazr
sazr

Reputation: 25938

Print a string and display the newlines & tabs in their character format

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

Upvotes: 1

Views: 1658

Answers (2)

Alex
Alex

Reputation: 6159

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

Sample Regular Expressions

Upvotes: 0

mmdemirbas
mmdemirbas

Reputation: 9158

html = html.Replace("\r", "\\r").Replace("\n","\\n").Replace("\t","\\t");

Upvotes: 4

Related Questions