Re: What's the syntax for a "char" constant? How about an hex integer?



Cosmin Prund wrote:
> 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

.



Relevant Pages

  • Re: CFile::Read problem ???
    ... As far as the C compiler is concerned, ... you can pretty much always assign a char ... as ASCII and wchar_t as Unicode. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: SecEdit INF format
    ... > I am a relative newbie in the area of vbscripting. ... > the file is an ASCII or a Unicode file in vbscript? ... Const ForWrite = 2 ... Handles the file for you whether ASCII or Unicode ...
    (microsoft.public.win2000.security)
  • Re: CFile::Read problem ???
    ... As far as the C compiler is concerned, ... you can pretty much always assign a char ... > as ASCII and wchar_t as Unicode. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: WCHAR
    ... Why are you using char and WCHAR in your code? ... you should be using is TCHAR, ... Also, you may very well have some part of your soft in Unicode, and ... with an old serial device using an ASCII protocol. ...
    (microsoft.public.vc.language)
  • Re: CString to const char*
    ... Which one is used depends on whether UNICODE is defined or not... ... Casting the result to char* won't convet the string from ASCII to ...
    (microsoft.public.vc.language)