473,472 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Hi,

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

Thanks.
Nov 16 '05 #1
5 35839
Nick <ni*****@heha.net.tw> wrote:
I would like to know what method can show the unicode value of string
and char in C#


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Thanks

Jon Skeet [C# MVP] wrote:
Nick <ni*****@heha.net.tw> wrote:
I would like to know what method can show the unicode value of string
and char in C#

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);
}

Nov 16 '05 #3
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,

Stefan
Nov 16 '05 #4
long is a System.Int64, you'd be better using a short, since it's a 16bit
type like char.

Etienne Boucher

"Stefan Holdermans" <st****@mimmick.nl> a écrit dans le message de
news:41**************@mimmick.nl...
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,

Stefan

Nov 16 '05 #5
Etienne Boucher <et*****@novat.qc.ca> wrote:
long is a System.Int64, you'd be better using a short, since it's a 16bit
type like char.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

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

Similar topics

16
by: Charles Kerekes | last post by:
Hello everyone, I am still learning C++, so I'm not sure what I'm trying to do is possible. Her is a simplified example: char Test = 'L'; cout << "Test Char as decimal: " << dec << Test <<...
4
by: Sumedha Swamy | last post by:
Hi, I would like to print the int value of Ü . The value is 220 (0xDC). Here is a program that I worte. But this prints the value 0. Where am I going wrong ? #include <string> #include...
1
by: VM | last post by:
How would I need to call MessageBox.Show() so it displays a variable of type char of 9 chars (char) ? If I use it normally (MessageBox.Show (myVar.ToString()); ), it displays System.Char. ...
15
by: Craig Wagner | last post by:
I have a situation where I have a series of character codes stored in the database. In some cases they are the ASCII value of the character, in other cases they are the > 127 character code value...
2
by: Gidi | last post by:
Hi, I'm writing a C# win application program, and i need to transfer my hebrew letters from unicode to ascii, now if i use the ascii encoding it writes me ??? instead of the hebrew letter i've...
3
by: Zach | last post by:
Hello, This might be a rather basic question, but I've tried a few things and I can't really find a solution as elegant as what I'd like for this problem. The situation is this - I have a file...
5
by: Jon Bowlas | last post by:
Hi listers, I wrote this script in Zope some time ago and it worked for a while, but now I'm getting the following error: TypeError: coercing to Unicode: need string or buffer, NoneType found ...
9
by: thijs.braem | last post by:
Hi everyone, I'm having quite some troubles trying to convert Unicode to String (for use in psycopg, which apparently doesn't know how to cope with unicode strings). The error I keep having...
3
by: OKB (not okblacke) | last post by:
I'm trying to write a unicode raw string literal, and I seem to be running up against a conflict between the \uXXXX unicode character escape and the need to have a literal \u (i.e., backslash...
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...
1
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.