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

Removing escape sequences from strings

P: n/a
JJ
Is there a way of checking that a line with escape sequences in it, has no
strings in it (apart from the escape sequences)?

i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it
a line with \n\t\t\t\thello\t\t\n would hve the string 'hello' in it.

In others words, is there a method of removing all escape sequences from a
string?

I've tried Regex.Unescape(string) but this doesn't not seem to remove the
sequences.
Is there a way, or do I have to try and remove all the possible excape
sequences by parsing the string?

Thanks,
JJ
Jun 9 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Have you tried just replacing them with nothing? If it's a string you could
do this like myString.Replace("\t","").Replace("\n","")
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"JJ" <ab*@xyz.comwrote in message
news:ez**************@TK2MSFTNGP03.phx.gbl...
Is there a way of checking that a line with escape sequences in it, has no
strings in it (apart from the escape sequences)?

i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it
a line with \n\t\t\t\thello\t\t\n would hve the string 'hello' in it.

In others words, is there a method of removing all escape sequences from a
string?

I've tried Regex.Unescape(string) but this doesn't not seem to remove the
sequences.
Is there a way, or do I have to try and remove all the possible excape
sequences by parsing the string?

Thanks,
JJ

Jun 9 '07 #2

P: n/a
"JJ" <ab*@xyz.comwrote in message
news:ez**************@TK2MSFTNGP03.phx.gbl...
Is there a way of checking that a line with escape sequences in it, has no
strings in it (apart from the escape sequences)?

i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it
a line with \n\t\t\t\thello\t\t\n would hve the string 'hello' in it.

In others words, is there a method of removing all escape sequences from a
string?

I've tried Regex.Unescape(string) but this doesn't not seem to remove the
sequences.
Is there a way, or do I have to try and remove all the possible excape
sequences by parsing the string?

There may be a "cleverer" more efficient way of doing this, but how about:

string strEscaped = "\n\t\t\t\thello\t\t\n";
string strUnescaped = strUnescaped.Replace("\n",
"").Replace("\t","").Replace("\r","");
--
http://www.markrae.net

Jun 9 '07 #3

P: n/a
JJ
Thats what I ended up doing (string.replace). My worry was that there seems
to be a lot of these possible escape sequences beyond the standard \r \t \n
etc. so I foolishly thought that there might be a 'built-in' method that
removes all possible sequences.

Thanks again,
John
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:us**************@TK2MSFTNGP05.phx.gbl...
"JJ" <ab*@xyz.comwrote in message
news:ez**************@TK2MSFTNGP03.phx.gbl...
>Is there a way of checking that a line with escape sequences in it, has
no strings in it (apart from the escape sequences)?

i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it
a line with \n\t\t\t\thello\t\t\n would hve the string 'hello' in it.

In others words, is there a method of removing all escape sequences from
a string?

I've tried Regex.Unescape(string) but this doesn't not seem to remove the
sequences.
Is there a way, or do I have to try and remove all the possible excape
sequences by parsing the string?


There may be a "cleverer" more efficient way of doing this, but how about:

string strEscaped = "\n\t\t\t\thello\t\t\n";
string strUnescaped = strUnescaped.Replace("\n",
"").Replace("\t","").Replace("\r","");
--
http://www.markrae.net

Jun 9 '07 #4

P: n/a
"JJ" <ab*@xyz.comwrote in message
news:u1**************@TK2MSFTNGP04.phx.gbl...
My worry was that there seems to be a lot of these possible escape
sequences
In fact, there are only a handful:
http://msdn2.microsoft.com/en-us/lib...7e(VS.80).aspx

Seems like a good candidate for a static method:

public static string StripEscape(string pstrText)
{
string strStrippedText = pstrText;

strStrippedText = strStrippedText.Replace("\t", String.Empty);
strStrippedText = strStrippedText.Replace("\n", String.Empty);

// etc

return strStrippedText;
}

Obviously, the list of escape characters may change in future versions of
C#...
--
http://www.markrae.net

Jun 9 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.