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 4 4253
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
"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
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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
by: kartik |
last post by:
Escape sequences don't seem to work in strings within list comprehensions:
>>> print ]
What am I missing?
Thank you.
|
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
|
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...
|
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. ...
|
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...
|
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,
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |