Re: Character representation

From: James Curran (JamesCurran_at_mvps.org)
Date: 10/08/04


Date: Fri, 8 Oct 2004 13:31:29 -0400


"Gas" <gasxxx@hotmail.com> wrote in message
news:ukv7nvUrEHA.2732@TK2MSFTNGP09.phx.gbl...

> Also is there any character to ASCII code and ASCII code to character
> built-in function in C#?

    One of the things that programmers coming from Basic language variant to
a C language variant have trouble with is that Basic imposes a completely
unnecessary distinction between numbers & characters, which C (and C++ and
C#) does not. So, the following code will print " A, 66":

public class MyClass
{
 public static void Main()
 {
    Char c =(Char) 65;
  int i = 'B';
  Console.WriteLine("{0}, {1}", c, i);
 }
}

Note that the cast it required to convert 65 to a character, but not to
convert 'B' into an int.

> I am wondering how can I representation some of the special characters in
> C#?
> (for example, we use vbKeyTab for Tab and vbCrLf for line feed in VB)

    So, with the above in mind, you can create Tab as a character simply by:

    char csKeyTab = (char) 9;

    However, you'll probably want them as string (and for vbCrLf, it would
have to be), inwhich case you can use the predefined "escape codes":

    string csCrLf = "\r\n";
    string csKeyTab = "\t";

    But say you want a string containing a special character which doesn't
have a predefined code? This can be done also, but you'll have to translate
the ASCII code into Hexadecimal.

    string csABC = "\x41\x42\x43"; // "ABC" "A" = ASCII 65 (dec) = 41
(hex)

-- 
Truth,
James Curran
Home: www.noveltheory.com       Work: www.njtheater.com
Blog: www.honestillusion.com  Day Job: www.partsearch.com
                                                (note new day job!)


Relevant Pages

  • Re: How to convert Infix notation to postfix notation
    ... int intMaxLength) ... array of 15 characters, and you call this function with the limit 15 on ... int appendPolish(char *strPolish, char chrNext) ... give a message like "string too long". ...
    (comp.lang.c)
  • Re: Checking for a keypress on Linux ?????
    ... the short delay in kbhit() ... > int getch; ... > * returns the number of characters available to read. ... > static struct termios Otty, ...
    (comp.os.linux.development.apps)
  • Re: [PATCH] Fix console utf8 composing
    ... So, the result is that the result of the composing operation is still taken from the accent_table, and thus cannot be more than "unsigned char" allows. ... in UTF-8 mode, it is possible to generate characters from Latin-1 set by composing, and they are generated correctly. ... +static int use_unicode; ...
    (Linux-Kernel)
  • Re: K&R Exercise 1-21: entab
    ... abc     _def ... when the resultant spacing was ... int tabreplace ... You've got "abc", which is three characters, plus five ...
    (comp.lang.c)
  • Re: [PATCH] console UTF-8 fixes
    ... as substitute glyph ... don't ignore zero-width characters (except for a few zero-width spaces ... print an extra space for double-wide characters for the cursor to stand ... int first; ...
    (Linux-Kernel)

Loading