[newby] What's the syntax for a "char" constant? How about an hex integer?

  • Thread starter Thread starter Cosmin Prund
  • Start date Start date
C

Cosmin Prund

This is supposed to be very easy, only I did not find this in MSDN so I'll
ask here:

How do I enter a char constant using the char's ASCII number? Specifically I
want to be able to compare a char to one of CR, LF, TAB (i.e: char number
13, 10, 9).

I suppose there's a problem because c#'s char's are unicode and I'm talking
ascii codes, but there must be a way to do it!

If I wore programming Delphi I would simply say
<code>
const c = #13;
</code>
for a const representing CR.

And while I'm at it, how do I enter a constant integer using HEX notation or
BINARY? Again, if I wore programming Delphi I would do something like this:
<code>
const i = $1234;
</code>
 
Cosmin said:
This is supposed to be very easy, only I did not find this in MSDN so I'll
ask here:

How do I enter a char constant using the char's ASCII number? Specifically I
want to be able to compare a char to one of CR, LF, TAB (i.e: char number
13, 10, 9).

The best way of doing those three is '\r', '\n' and '\t'. However, you
*can* use:
'\u000d' '\u000a' and '\u0009'

Alternatively, just:

const char CR = (char)13;
I suppose there's a problem because c#'s char's are unicode and I'm talking
ascii codes, but there must be a way to do it!

Fortunately all ASCII characters have the same value in Unicode.
And while I'm at it, how do I enter a constant integer using HEX notation or
BINARY? Again, if I wore programming Delphi I would do something like this:
<code>
const i = $1234;
</code>

const int i = 0x1234;

Jon
 
Thanks a lot!

Jon Skeet said:
The best way of doing those three is '\r', '\n' and '\t'. However, you
*can* use:
'\u000d' '\u000a' and '\u0009'

Alternatively, just:

const char CR = (char)13;


Fortunately all ASCII characters have the same value in Unicode.


const int i = 0x1234;

Jon
 

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

Back
Top