472,969 Members | 1,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 software developers and data experts.

Removing escape sequences from strings

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
4 4230
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Philips | last post by:
I have been playing around with reading strings with embedded escape sequences from files both using readline() and codecs.open() and have a question.I create a file "test.txt" with exactly one...
6
by: Paul Watson | last post by:
How can I get the escapes from a command line parameter interpreted? The user provides a string on the command line. The string might contain traditional escapes such as \t, \n, etc. It might...
6
by: kartik | last post by:
Escape sequences don't seem to work in strings within list comprehensions: >>> print ] What am I missing? Thank you.
8
by: Joe | last post by:
I'm using Python 2.4 on Windows XP SP2. I'm trying to receive a command line argument that is a newline (\n) Here is the command line to use sample.py "\n" Here is a sample.py script
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
3
by: Ken | last post by:
HI: I'm reading a string that will be displayed in a MessageBox from a resource file. The string in the resource file contains escape sequences so they will be broken up into multiple lines. ...
5
by: nummertolv | last post by:
Hi, My application is receiving strings, representing windows paths, from an external source. When using these paths, by for instance printing them using str() (print path), the backslashes are...
3
by: slomo | last post by:
How to read strings cantaining escape character from a file and use it as escape sequences? for example, a file 'unicodes.txt' has contents: \u0050\u0079\u0074\u0068\u006f\u006e Now, ...
10
by: hanaa | last post by:
Hello there. $str="This is \na ball"; echo $str; Is there a way i can make the text to be as is, without expanding the escape sequences. I know that single quoted strings do not expand escape...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.