Re: Character representation
From: Gas (gasxxx_at_hotmail.com)
Date: 10/12/04
- Next message: Štefan Šimek: "Re: Smart way to connect enums to string values"
- Previous message: Michael C: "Re: Error when closing application"
- In reply to: James Curran: "Re: Character representation"
- Next in thread: Jon Skeet [C# MVP]: "Re: Character representation"
- Reply: Jon Skeet [C# MVP]: "Re: Character representation"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 12 Oct 2004 09:39:42 -0400
Just wondering do I really need the casting in C# here?
because I know in C++,
Char c= 65; will work
Gas
"James Curran" <JamesCurran@mvps.org> wrote in message
news:u9B3$yVrEHA.3712@TK2MSFTNGP15.phx.gbl...
> "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!)
>
>
- Next message: Štefan Šimek: "Re: Smart way to connect enums to string values"
- Previous message: Michael C: "Re: Error when closing application"
- In reply to: James Curran: "Re: Character representation"
- Next in thread: Jon Skeet [C# MVP]: "Re: Character representation"
- Reply: Jon Skeet [C# MVP]: "Re: Character representation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|