Groups | Blog | Home
all groups > c# > august 2004 >

c# : How to show Unicode value of a string/char in C#


Jon Skeet [C# MVP]
8/22/2004 3:23:29 PM
[quoted text, click to view]

Well, a string is just a series of characters, so access each one in
turn. You can find the unicode value of a character by just casting it
char. For instance, this prints out the unicode value of each character
in a string:

foreach (char c in theString)
{
Console.WriteLine ((int)c);
}

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Stefan Holdermans
8/22/2004 9:02:21 PM
Nick,

N> I would like to know what method can show the unicode value of string
N> and char in C#

using System;

class UnicodeValues {
static void Main() {¹
char c = (char) 0x0023; // '#'¹
long l = (long) c;
Console.WriteLine(c.ToString());
Console.WriteLine(l.ToString());
}
}

HTH,

Etienne Boucher
8/22/2004 9:26:44 PM
long is a System.Int64, you'd be better using a short, since it's a 16bit
type like char.

Etienne Boucher

"Stefan Holdermans" <stefan@mimmick.nl> a écrit dans le message de
news:412909DC.2040603@mimmick.nl...
[quoted text, click to view]

Nick
8/22/2004 9:55:34 PM
Hi,

I would like to know what method can show the unicode value of string
and char in C#

Nick
8/22/2004 10:37:51 PM
Thanks

[quoted text, click to view]
Jon Skeet [C# MVP]
8/23/2004 8:06:32 AM
[quoted text, click to view]

I personally tend to use int. Short would be okay, but ushort would be
better, as that's an unsigned 16-bit type like char.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button