Escape Character \e does not work

G

Guest

I am having a problem with the "escape" character \e. This code is in my
Windows form KeyPress event. The compiler gives me "unrecognized escape
sequence" even though this is documented in MSDN. Any idea if this is a bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

pkaeowic said:
I am having a problem with the "escape" character \e. This code is in my
Windows form KeyPress event. The compiler gives me "unrecognized escape
sequence" even though this is documented in MSDN. Any idea if this is a
bug?

if (e.KeyChar == '\e')
{
this.Close();
}

Weird, here happens the same, it said it's not recignized, even when MSND
says it's valid.

Workaround: just use the value:
if e.KeyChar == (char)27 )
 
S

Stoitcho Goutsev \(100\)

Where is this in MSDN?
I'm looking at C# language reference - "2.4.4.4 Character literals"
and here are the escape codes:

\' \" \\ \0 \a \b \f \n \r \t \v

I don't see \e. What is it anyways?
 
V

vj

this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ
 
S

Stoitcho Goutsev \(100\)

Of course this will work. Putting @ infront of a string means that you are
not going to use escape sequences, so your string contains two characters -
\ and e.
sCal.ToCharArray()[0]) returns \ in this case which is not \e, whatever this
esc char must be.



--

Stoitcho Goutsev (100)

vj said:
this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ

pkaeowic said:
I am having a problem with the "escape" character \e. This code is in my
Windows form KeyPress event. The compiler gives me "unrecognized escape
sequence" even though this is documented in MSDN. Any idea if this is a
bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
S

scott blood

Hello,

The actual escape sequence characters are as follows...

\b
Matches a backspace

\t
Matches a tab

\r
Matches a carriage return

\v
Matches a vertical tab

\f
Matches a form feed

\n
Matches a new line

\e
Matches an escape

\040
Matches an ASCII character as octal (up to three digits);

\x20
Matches an ASCII character using hexadecimal representation (exactly
two digits).

\cC
Matches an ASCII control character; for example, \cC is control-C.

\u0020
Matches a Unicode character using hexadecimal representation (exactly
four digits).




Regards
Scott Blood
C# Developer

Stoitcho Goutsev (100) said:
Of course this will work. Putting @ infront of a string means that you are
not going to use escape sequences, so your string contains two
characters - \ and e.
sCal.ToCharArray()[0]) returns \ in this case which is not \e, whatever
this esc char must be.



--

Stoitcho Goutsev (100)

vj said:
this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ

pkaeowic said:
I am having a problem with the "escape" character \e. This code is in my
Windows form KeyPress event. The compiler gives me "unrecognized escape
sequence" even though this is documented in MSDN. Any idea if this is a
bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
S

Stoitcho Goutsev \(100\)

Again, can somebody point me to the place in the docs where this \e is
mentioned because the set of esc chars that I posted came from the C#
specifications and I don't know more reliable source.

Scott, where did you get that list from?


--

Stoitcho Goutsev (100)

scott blood said:
Hello,

The actual escape sequence characters are as follows...

\b
Matches a backspace

\t
Matches a tab

\r
Matches a carriage return

\v
Matches a vertical tab

\f
Matches a form feed

\n
Matches a new line

\e
Matches an escape

\040
Matches an ASCII character as octal (up to three digits);

\x20
Matches an ASCII character using hexadecimal representation (exactly
two digits).

\cC
Matches an ASCII control character; for example, \cC is control-C.

\u0020
Matches a Unicode character using hexadecimal representation (exactly
four digits).




Regards
Scott Blood
C# Developer

Stoitcho Goutsev (100) said:
Of course this will work. Putting @ infront of a string means that you
are not going to use escape sequences, so your string contains two
characters - \ and e.
sCal.ToCharArray()[0]) returns \ in this case which is not \e, whatever
this esc char must be.



--

Stoitcho Goutsev (100)

vj said:
this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ

I am having a problem with the "escape" character \e. This code is in my
Windows form KeyPress event. The compiler gives me "unrecognized escape
sequence" even though this is documented in MSDN. Any idea if this is a
bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
S

scott blood

Stoitcho,

I got my list from the following link.

www.exforsys.com/content/view/1749/360/

Regards
Scott Blood
C# Developer

Stoitcho Goutsev (100) said:
Again, can somebody point me to the place in the docs where this \e is
mentioned because the set of esc chars that I posted came from the C#
specifications and I don't know more reliable source.

Scott, where did you get that list from?


--

Stoitcho Goutsev (100)

scott blood said:
Hello,

The actual escape sequence characters are as follows...

\b
Matches a backspace

\t
Matches a tab

\r
Matches a carriage return

\v
Matches a vertical tab

\f
Matches a form feed

\n
Matches a new line

\e
Matches an escape

\040
Matches an ASCII character as octal (up to three digits);

\x20
Matches an ASCII character using hexadecimal representation (exactly
two digits).

\cC
Matches an ASCII control character; for example, \cC is control-C.

\u0020
Matches a Unicode character using hexadecimal representation (exactly
four digits).




Regards
Scott Blood
C# Developer

Stoitcho Goutsev (100) said:
Of course this will work. Putting @ infront of a string means that you
are not going to use escape sequences, so your string contains two
characters - \ and e.
sCal.ToCharArray()[0]) returns \ in this case which is not \e, whatever
this esc char must be.



--

Stoitcho Goutsev (100)

this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ

I am having a problem with the "escape" character \e. This code is in
my
Windows form KeyPress event. The compiler gives me "unrecognized
escape
sequence" even though this is documented in MSDN. Any idea if this is
a bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

M

Marc Gravell

That is regex syntax, not C# string syntax; in C#, that would be "\\e" or
@"\e"

Marc

scott blood said:
Stoitcho,

I got my list from the following link.

www.exforsys.com/content/view/1749/360/

Regards
Scott Blood
C# Developer

Stoitcho Goutsev (100) said:
Again, can somebody point me to the place in the docs where this \e is
mentioned because the set of esc chars that I posted came from the C#
specifications and I don't know more reliable source.

Scott, where did you get that list from?


--

Stoitcho Goutsev (100)

scott blood said:
Hello,

The actual escape sequence characters are as follows...

\b
Matches a backspace

\t
Matches a tab

\r
Matches a carriage return

\v
Matches a vertical tab

\f
Matches a form feed

\n
Matches a new line

\e
Matches an escape

\040
Matches an ASCII character as octal (up to three digits);

\x20
Matches an ASCII character using hexadecimal representation (exactly
two digits).

\cC
Matches an ASCII control character; for example, \cC is control-C.

\u0020
Matches a Unicode character using hexadecimal representation
(exactly four digits).




Regards
Scott Blood
C# Developer

Of course this will work. Putting @ infront of a string means that you
are not going to use escape sequences, so your string contains two
characters - \ and e.
sCal.ToCharArray()[0]) returns \ in this case which is not \e, whatever
this esc char must be.



--

Stoitcho Goutsev (100)

this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ

I am having a problem with the "escape" character \e. This code is in
my
Windows form KeyPress event. The compiler gives me "unrecognized
escape
sequence" even though this is documented in MSDN. Any idea if this is
a bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

See my other post here, it comes from a regex help page,

The bad part is that when searched c# "character escape"
site:msdn.microsoft.com the second match is for the error the OP had, the
link in that page (where suppostely tell you the VALID c# chars) takes you
to a page
http://msdn.microsoft.com/library/d...en-us/cpgenref/html/cpconCharacterEscapes.asp
where \e is listed



--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Stoitcho Goutsev (100) said:
Again, can somebody point me to the place in the docs where this \e is
mentioned because the set of esc chars that I posted came from the C#
specifications and I don't know more reliable source.

Scott, where did you get that list from?


--

Stoitcho Goutsev (100)

scott blood said:
Hello,

The actual escape sequence characters are as follows...

\b
Matches a backspace

\t
Matches a tab

\r
Matches a carriage return

\v
Matches a vertical tab

\f
Matches a form feed

\n
Matches a new line

\e
Matches an escape

\040
Matches an ASCII character as octal (up to three digits);

\x20
Matches an ASCII character using hexadecimal representation (exactly
two digits).

\cC
Matches an ASCII control character; for example, \cC is control-C.

\u0020
Matches a Unicode character using hexadecimal representation (exactly
four digits).




Regards
Scott Blood
C# Developer

Stoitcho Goutsev (100) said:
Of course this will work. Putting @ infront of a string means that you
are not going to use escape sequences, so your string contains two
characters - \ and e.
sCal.ToCharArray()[0]) returns \ in this case which is not \e, whatever
this esc char must be.



--

Stoitcho Goutsev (100)

this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ

I am having a problem with the "escape" character \e. This code is in
my
Windows form KeyPress event. The compiler gives me "unrecognized
escape
sequence" even though this is documented in MSDN. Any idea if this is
a bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
S

Stoitcho Goutsev \(100\)

Ignacio,

As you correctly stated these are Regular Expression's escape sequences.
They have nothing to do with the C# language.

For example VB.NET, as far as I know, doesn't support escape seqs at all.
We can't just look for any document that just lists escape characters.




Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

See my other post here, it comes from a regex help page,

The bad part is that when searched c# "character escape"
site:msdn.microsoft.com the second match is for the error the OP had, the
link in that page (where suppostely tell you the VALID c# chars) takes you
to a page
http://msdn.microsoft.com/library/d...en-us/cpgenref/html/cpconCharacterEscapes.asp
where \e is listed



--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Stoitcho Goutsev (100) said:
Again, can somebody point me to the place in the docs where this \e is
mentioned because the set of esc chars that I posted came from the C#
specifications and I don't know more reliable source.

Scott, where did you get that list from?


--

Stoitcho Goutsev (100)

scott blood said:
Hello,

The actual escape sequence characters are as follows...

\b
Matches a backspace

\t
Matches a tab

\r
Matches a carriage return

\v
Matches a vertical tab

\f
Matches a form feed

\n
Matches a new line

\e
Matches an escape

\040
Matches an ASCII character as octal (up to three digits);

\x20
Matches an ASCII character using hexadecimal representation (exactly
two digits).

\cC
Matches an ASCII control character; for example, \cC is control-C.

\u0020
Matches a Unicode character using hexadecimal representation
(exactly four digits).




Regards
Scott Blood
C# Developer

Of course this will work. Putting @ infront of a string means that you
are not going to use escape sequences, so your string contains two
characters - \ and e.
sCal.ToCharArray()[0]) returns \ in this case which is not \e, whatever
this esc char must be.



--

Stoitcho Goutsev (100)

this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ

I am having a problem with the "escape" character \e. This code is in
my
Windows form KeyPress event. The compiler gives me "unrecognized
escape
sequence" even though this is documented in MSDN. Any idea if this is
a bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
T

Tom Porterfield

pkaeowic said:
I am having a problem with the "escape" character \e. This code is in my
Windows form KeyPress event. The compiler gives me "unrecognized escape
sequence" even though this is documented in MSDN. Any idea if this is a
bug?

if (e.KeyChar == '\e')
{
this.Close();
}

You should look at doing the following instead:

if (e.KeyChar == (char)Keys.Escape)
{
this.Close();
}
 
V

vj

I can't find it in MSDN either...

VJ

vj said:
this seems to work ok...

string sCal = @"\e";

if (e.KeyChar == sCal.ToCharArray()[0])
{
this.Close();
}

Really weird.. problem

VJ

pkaeowic said:
I am having a problem with the "escape" character \e. This code is in my
Windows form KeyPress event. The compiler gives me "unrecognized escape
sequence" even though this is documented in MSDN. Any idea if this is a
bug?

if (e.KeyChar == '\e')
{
this.Close();
}
 
G

Guest

Tom that is the better way to do it.

Thanks.



Tom Porterfield said:
You should look at doing the following instead:

if (e.KeyChar == (char)Keys.Escape)
{
this.Close();
}
 

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