473,513 Members | 13,099 Online
Bytes | Software Development & Data Engineering Community
+ 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 35863
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
422
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
2166
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
2803
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
9797
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
3534
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
1911
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
19986
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
15718
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
2304
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
7153
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
7432
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
5677
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,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
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
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
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.