473,804 Members | 3,675 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 35955
Nick <ni*****@heha.n et.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.WriteLi ne ((int)c);
}

--
Jon Skeet - <sk***@pobox.co m>
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.n et.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.WriteLi ne ((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.WriteLi ne(c.ToString() );
Console.WriteLi ne(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.WriteLi ne(c.ToString() );
Console.WriteLi ne(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.co m>
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 << endl; In the above cout statement, I was hoping it would show 76, the decimal value of the L character. Instead, it displays an L. Is there
4
2184
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 <iostream> using namespace std; int main() {
1
2819
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. Thanks.
15
9833
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 that you use in combination with the ALT key to enter special characters into a document (e.g. ALT+0147 and ALT+0148 get you 'smart quotes'). I'm trying to figure out how (or if it's possible) to obtain the Unicode equivalent of the character...
2
3549
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 entered. I know what the Ascii value of each letter, so i understood that i can transfer my string to BYTE and enter the ascii value by myself. if someone has a better idea, i'll be happy to hear about it. how can i know the Unicode value of a...
3
1934
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 that's written to disk in a binary format. Basically it's a bunch of records, one after the other, where each record has the following format : 18 bytes, 6 bytes which are all zero, 4 bytes which represent a UInt32. The first 18 bytes of each...
5
20018
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 Here's my script: results = context.module_retriever().tuples() # call to ZSQLMethod converted =
9
15744
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 is something like this: ERREUR: Séquence d'octets invalide pour le codage «UTF8» : 0xe02063 (sorry, locale is french, it means "byte sequence invalid for encoding
3
2329
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 followed by a lowercase letter U) in the string. If I do ur"\universe" I get a UnicodeDecodeError because (I think) it tries to interpret \universe as a Unicode escape. But if I do ur"\\universe" I get a string that contains two backslashes...
0
9707
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10586
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.