473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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>
Nov 18 '05 #1
2 2930
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

Nov 18 '05 #2
Thanks a lot!

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: eyal.susser | last post by:
Hi, I'm curious. I've seen code with methods that can somehow tell a char* from a char. How? I've tried using a template like this template <size_t size> void & discriminate(char s) {...
37
by: Debajit Adhikary | last post by:
Now I know (from Stroustrup's site) that "char" is pronounced "tchar" and not "kar". Does the same hold true largely in the C world?
20
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
14
by: Anna | last post by:
I try to put 8 int bit for example 10100010 into one character of type char(1 octet) with no hope . Could anyone propose a simple way to do it? Thank you very much.
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.