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

Escape Character \e does not work

P: n/a
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();
}
Mar 23 '06 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Hi,

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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 )

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 23 '06 #2

P: n/a
Thanks for the reply Ignacio. That's what I ended up doing.

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

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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 )

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

Mar 23 '06 #3

P: n/a
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?
--

Stoitcho Goutsev (100)

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Thanks for the reply Ignacio. That's what I ended up doing.

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

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
>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 )

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

Mar 23 '06 #4

P: n/a
vj
this seems to work ok...

string sCal = @"\e";

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

Really weird.. problem

VJ

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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();
}

Mar 23 '06 #5

P: n/a
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" <vi********@yahoo.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
this seems to work ok...

string sCal = @"\e";

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

Really weird.. problem

VJ

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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();
}


Mar 24 '06 #6

P: n/a
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)" <10*@100.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...
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" <vi********@yahoo.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
this seems to work ok...

string sCal = @"\e";

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

Really weird.. problem

VJ

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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();
}



Mar 24 '06 #7

P: n/a
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" <sc*********@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl...
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)" <10*@100.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...
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" <vi********@yahoo.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
this seems to work ok...

string sCal = @"\e";

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

Really weird.. problem

VJ

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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();
}



Mar 24 '06 #8

P: n/a
Stoitcho,

I got my list from the following link.

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

Regards
Scott Blood
C# Developer

"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
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" <sc*********@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl...
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)" <10*@100.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...
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" <vi********@yahoo.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
this seems to work ok...

string sCal = @"\e";

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

Really weird.. problem

VJ

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
>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();
> }



Mar 24 '06 #9

P: n/a
HI,
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:ez**************@TK2MSFTNGP14.phx.gbl...
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?


It's in the ".NET Framework General Reference" ,"Character Escapes"
http://msdn.microsoft.com/library/de...terescapes.asp

But it does refer to regex , not to the sequences recognized by the compiler
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 24 '06 #10

P: n/a
That is regex syntax, not C# string syntax; in C#, that would be "\\e" or
@"\e"

Marc

"scott blood" <sc*********@hotmail.com> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
Stoitcho,

I got my list from the following link.

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

Regards
Scott Blood
C# Developer

"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
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" <sc*********@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl...
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)" <10*@100.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...
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" <vi********@yahoo.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
> this seems to work ok...
>
> string sCal = @"\e";
>
> if (e.KeyChar == sCal.ToCharArray()[0])
> {
> this.Close();
> }
>
> Really weird.. problem
>
> VJ
>
> "pkaeowic" <pk******@discussions.microsoft.com> wrote in message
> news:8F**********************************@microsof t.com...
>>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();
>> }
>
>



Mar 24 '06 #11

P: n/a
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/de...terEscapes.asp
where \e is listed

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
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" <sc*********@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl...
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)" <10*@100.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...
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" <vi********@yahoo.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
this seems to work ok...

string sCal = @"\e";

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

Really weird.. problem

VJ

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
>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();
> }



Mar 24 '06 #12

P: n/a
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 )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uY****************@TK2MSFTNGP12.phx.gbl...
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/de...terEscapes.asp
where \e is listed

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
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" <sc*********@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl...
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)" <10*@100.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...
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" <vi********@yahoo.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
> this seems to work ok...
>
> string sCal = @"\e";
>
> if (e.KeyChar == sCal.ToCharArray()[0])
> {
> this.Close();
> }
>
> Really weird.. problem
>
> VJ
>
> "pkaeowic" <pk******@discussions.microsoft.com> wrote in message
> news:8F**********************************@microsof t.com...
>>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();
>> }
>
>



Mar 24 '06 #13

P: n/a
pkaeowic wrote:
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();
}

--
Tom Porterfield
Mar 24 '06 #14

P: n/a
vj
I can't find it in MSDN either...

VJ

"vj" <vi********@yahoo.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
this seems to work ok...

string sCal = @"\e";

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

Really weird.. problem

VJ

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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();
}


Mar 24 '06 #15

P: n/a
Tom that is the better way to do it.

Thanks.

"Tom Porterfield" wrote:
pkaeowic wrote:
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();
}

--
Tom Porterfield

Mar 31 '06 #16

This discussion thread is closed

Replies have been disabled for this discussion.