By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

String Manipulation - Escape Sequence

P: n/a
I need to place the following into a string... How can I properly escape the
% " / < and > characters?

<table width="100%" border="0" cellspacing="0" cellpadding="4px"
class="hfAll"></Table>

Thanks.
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi GMan:

The backslash will escape the " character. %, /, <, and > do not need
an escape sequence.

You can also use the @ symbol to start a verbatim string literal.

So:

Console.WriteLine("This \"is\" a %<>test\\");
Console.WriteLine(@"This ""is"" a %<>test\");

both print out This "is" a %<>test\

For your string I'd just escape all the " characters with \.

HTH,
--
Scott
http://www.OdeToCode.com

On Tue, 17 Aug 2004 18:56:55 -0700, "Guadala Harry" <GM**@NoSpam.com>
wrote:
I need to place the following into a string... How can I properly escape the
% " / < and > characters?

<table width="100%" border="0" cellspacing="0" cellpadding="4px"
class="hfAll"></Table>

Thanks.


Nov 16 '05 #2

P: n/a
The only thing needed to escape here are the doublequote and you escape it
using the backslash. For instance

string html = "<table width=\"100%\" border .... >"

Matias Woloski
southworks.net

"Guadala Harry" <GM**@NoSpam.com> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl...
I need to place the following into a string... How can I properly escape the % " / < and > characters?

<table width="100%" border="0" cellspacing="0" cellpadding="4px"
class="hfAll"></Table>

Thanks.

Nov 16 '05 #3

P: n/a
Thanks - I got into trouble when I used both the @ symbol and the \ escape
character... I received the IDE/tooltop message "; expected" That's why I
thought I needed to escape more than just the " character - but could find
no references including the other characters in the "need to escape these"
lists.

oh the joys of being a C# beginner...

: )

-G

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:g7********************************@4ax.com...
Hi GMan:

The backslash will escape the " character. %, /, <, and > do not need
an escape sequence.

You can also use the @ symbol to start a verbatim string literal.

So:

Console.WriteLine("This \"is\" a %<>test\\");
Console.WriteLine(@"This ""is"" a %<>test\");

both print out This "is" a %<>test\

For your string I'd just escape all the " characters with \.

HTH,
--
Scott
http://www.OdeToCode.com

On Tue, 17 Aug 2004 18:56:55 -0700, "Guadala Harry" <GM**@NoSpam.com>
wrote:
I need to place the following into a string... How can I properly escape the% " / < and > characters?

<table width="100%" border="0" cellspacing="0" cellpadding="4px"
class="hfAll"></Table>

Thanks.

Nov 16 '05 #4

P: n/a
Guadala Harry wrote:
Thanks - I got into trouble when I used both the @ symbol and the \ escape
character...
That's because in a 'verbatim string literal' (one preceded by the @
character), escaping is done differently and can only be done for the
double-quote character:

string s1 = @" "" "; // this is a lone double-quote char
// surrounded by some spaces

string s2 = " \" "; // the same string using standard
// character escaping

string s3 = @" \" "; // invalid syntax - you have a verbatim
// string that is some spaces with a
// backslash at the end. This is
// followed by a spurious double-
// quote char right before the semi-colon.
I received the IDE/tooltop message "; expected" That's why I
thought I needed to escape more than just the " character - but could find
no references including the other characters in the "need to escape these"
lists.

oh the joys of being a C# beginner...

: )

-G

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:g7********************************@4ax.com...
Hi GMan:

The backslash will escape the " character. %, /, <, and > do not need
an escape sequence.

You can also use the @ symbol to start a verbatim string literal.

So:

Console.WriteLine("This \"is\" a %<>test\\");
Console.WriteLine(@"This ""is"" a %<>test\");

both print out This "is" a %<>test\

For your string I'd just escape all the " characters with \.

HTH,
--
Scott
http://www.OdeToCode.com

On Tue, 17 Aug 2004 18:56:55 -0700, "Guadala Harry" <GM**@NoSpam.com>
wrote:

I need to place the following into a string... How can I properly escape
the
% " / < and > characters?

<table width="100%" border="0" cellspacing="0" cellpadding="4px"
class="hfAll"></Table>

Thanks.


--
mikeb
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.