What Happens To Escape Characters?

G

Guadala Harry

I'd like to know the answer to the following question so I can know what to
expect with regard to other similar uses of escape characters and strings.
While everything works fine - I'd like to know specifically why:

I am building a simple HTML table in my C# code-behind by concatenating
strings that contain different parts of the table and table content...
something like this:

string myTable = "<table width=\"100%\" border=\"0\" cellspacing=\"0\"
cellpadding=\"0px\" class=\"myCSSClass\"><tr><td>";

Notice the back-slash (\) character which is there to escape each of the
double-quote (") characters.

After the table is finished being constructed, it exists in one string
variable - which I HtmlEncode prior to returning to the caller.

The calling method then HtmlDecodes that string, and for testing purposes
renders to the browser via Response.Write(). The table renders just
beautifully. While that is good news, I'm curious as to what is happening to
the \ escape characters. They are all present in the HtmlDecoded string, of
course - which is fed into Response.Write(). The value of the string that
shows up in the browser (i.e., the <table> definition) does *not* have the
escape characters (at least as the browser shows the rendered page). So,
when were they removed, and what removed them?

In trying to determine where the escape characters are being removed (client
or server side), I pasted the string value with the escape characters (the
value that is fed to Response.Write()) directly into the ASPX file - and it
failed to render correctly, as all of the escape characters were present.
So, apparently the browser is not removing them. What specifically is
removing them?

Thanks!
 
L

Lau Lei Cheong

The escape characters are removed once you compile the project.

They are there to tell the compiler you really want to input a ' " ' and not
to terminate the string, so no point to keep them after the project is
built.
 
G

Guadala Harry

Thanks - now just to be clear - this all has *nothing* to do with browsers
or asp.net or html, and same would apply for any .NET project type?

-G
 
L

Lau Lei Cheong

Yes unless your code is on any of the client side script, where they are
sent as plain text to browsers and then get interpreted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top