473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Obtain Unicode value from Character Code?

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 code.

I've tried several variations of the following but so far none of them have
worked:

byte charCode = // get value from datatable
Encoding.ASCII.GetString( new byte [] { charCode } );

I also tried simply casting the charCode as a char, but of course that results
in a character using the charCode as a Unicode value, which gets me the wrong
character.

I found an example in JScript that does exactly what I want, but I'm writing in
C#. I only bring this up because it shows me that what I want to do is at least
possible, which leads me to believe there must be a way to do it.

Basically, I'm looking for an equivalent to the JScript charCodeAt method:

http://msdn.microsoft.com/library/en...charcodeat.asp

Any suggestions?
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"
Nov 16 '05 #1
15 9788
Hi Craig,

Didn't you try to get that char codes as "char" or "string"?

You can also try "Encoding.UTF8.GetString(...)".
If you'll get this string then [index] should do the job.

Regards

Marcin
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 code.

I've tried several variations of the following but so far none of them have
worked:

byte charCode = // get value from datatable
Encoding.ASCII.GetString( new byte [] { charCode } );

I also tried simply casting the charCode as a char, but of course that results
in a character using the charCode as a Unicode value, which gets me the wrong
character.

I found an example in JScript that does exactly what I want, but I'm writing in
C#. I only bring this up because it shows me that what I want to do is at least
possible, which leads me to believe there must be a way to do it.

Basically, I'm looking for an equivalent to the JScript charCodeAt method:

http://msdn.microsoft.com/library/en...charcodeat.asp

Any suggestions?
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"

Nov 16 '05 #2
Hi Craig,

Didn't you try to get that char codes as "char" or "string"?

You can also try "Encoding.UTF8.GetString(...)".
If you'll get this string then [index] should do the job.

Regards

Marcin
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 code.

I've tried several variations of the following but so far none of them have
worked:

byte charCode = // get value from datatable
Encoding.ASCII.GetString( new byte [] { charCode } );

I also tried simply casting the charCode as a char, but of course that results
in a character using the charCode as a Unicode value, which gets me the wrong
character.

I found an example in JScript that does exactly what I want, but I'm writing in
C#. I only bring this up because it shows me that what I want to do is at least
possible, which leads me to believe there must be a way to do it.

Basically, I'm looking for an equivalent to the JScript charCodeAt method:

http://msdn.microsoft.com/library/en...charcodeat.asp

Any suggestions?
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"

Nov 16 '05 #3
Craig Wagner <cr************@hotmail.com> wrote:
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').
<snip>
Any suggestions?


I *think* you're after Encoding.Default.

However, the database really ought to be able to know how it's stored
them and give you the text in Unicode. What's the type of the column,
what's the database in question, and how are you retrieving the
database?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Craig Wagner <cr************@hotmail.com> wrote:
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').
<snip>
Any suggestions?


I *think* you're after Encoding.Default.

However, the database really ought to be able to know how it's stored
them and give you the text in Unicode. What's the type of the column,
what's the database in question, and how are you retrieving the
database?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
However, the database really ought to be able to know how it's stored
them and give you the text in Unicode. What's the type of the column,
what's the database in question, and how are you retrieving the
database?


Sorry, the last bit of course should be "how are you retrieving the
value".

--
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
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
However, the database really ought to be able to know how it's stored
them and give you the text in Unicode. What's the type of the column,
what's the database in question, and how are you retrieving the
database?


Sorry, the last bit of course should be "how are you retrieving the
value".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
Craig Wagner <cr************@hotmail.com> wrote:
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').


<snip>
Any suggestions?


I *think* you're after Encoding.Default.

However, the database really ought to be able to know how it's stored
them and give you the text in Unicode. What's the type of the column,
what's the database in question, and how are you retrieving the
database?


The database has stored the value as an integer. The database isn't storing the
character, it's storing the character code (i.e. it's not storing the smart
quote, it's storing 147 as an integer).

The database is SQL Server 2000 and my C# code is calling a stored proc that is
used to populate a DataTable.
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"
Nov 16 '05 #8
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
Craig Wagner <cr************@hotmail.com> wrote:
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').


<snip>
Any suggestions?


I *think* you're after Encoding.Default.

However, the database really ought to be able to know how it's stored
them and give you the text in Unicode. What's the type of the column,
what's the database in question, and how are you retrieving the
database?


The database has stored the value as an integer. The database isn't storing the
character, it's storing the character code (i.e. it's not storing the smart
quote, it's storing 147 as an integer).

The database is SQL Server 2000 and my C# code is calling a stored proc that is
used to populate a DataTable.
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"
Nov 16 '05 #9
Craig Wagner <cr************@hotmail.com> wrote:
However, the database really ought to be able to know how it's stored
them and give you the text in Unicode. What's the type of the column,
what's the database in question, and how are you retrieving the
database?


The database has stored the value as an integer. The database isn't storing the
character, it's storing the character code (i.e. it's not storing the smart
quote, it's storing 147 as an integer).

The database is SQL Server 2000 and my C# code is calling a stored proc that is
used to populate a DataTable.


So it's storing a character as the integer value in an ill-defined
encoding? That doesn't sound like a terribly good idea, to be honest.

Anyway, Encoding.Default *might* do what you want it to, as I said
before - just put the integer value into a byte array as the sole
value, and call Encoding.GetString to get the appropriate string. If
the encoding is subtly different though, you'll have problems.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #10
Craig Wagner <cr************@hotmail.com> wrote:
However, the database really ought to be able to know how it's stored
them and give you the text in Unicode. What's the type of the column,
what's the database in question, and how are you retrieving the
database?


The database has stored the value as an integer. The database isn't storing the
character, it's storing the character code (i.e. it's not storing the smart
quote, it's storing 147 as an integer).

The database is SQL Server 2000 and my C# code is calling a stored proc that is
used to populate a DataTable.


So it's storing a character as the integer value in an ill-defined
encoding? That doesn't sound like a terribly good idea, to be honest.

Anyway, Encoding.Default *might* do what you want it to, as I said
before - just put the integer value into a byte array as the sole
value, and call Encoding.GetString to get the appropriate string. If
the encoding is subtly different though, you'll have problems.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #11
Marcin Grz?bski <mg*******@taxussi.no.com.spam.pl> wrote:
Didn't you try to get that char codes as "char" or "string"?
I'm not sure I understand the question. Do you mean from the database? I've only
got an integer in the database, but I could try doing the conversion to
character on the DB side rather than in my code.
You can also try "Encoding.UTF8.GetString(...)".
If you'll get this string then [index] should do the job.


That was one of the permutations I tried. The problem is it expects you to feed
it the Unicode value of the characters in the GetString argument, and I don't
have the Unicode value, that's what I'm trying to get.
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 code.

I've tried several variations of the following but so far none of them have
worked:

byte charCode = // get value from datatable
Encoding.ASCII.GetString( new byte [] { charCode } );

I also tried simply casting the charCode as a char, but of course that results
in a character using the charCode as a Unicode value, which gets me the wrong
character.

I found an example in JScript that does exactly what I want, but I'm writing in
C#. I only bring this up because it shows me that what I want to do is at least
possible, which leads me to believe there must be a way to do it.

Basically, I'm looking for an equivalent to the JScript charCodeAt method:

http://msdn.microsoft.com/library/en...charcodeat.asp

Any suggestions?
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"


---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"
Nov 16 '05 #12
Marcin Grz?bski <mg*******@taxussi.no.com.spam.pl> wrote:
Didn't you try to get that char codes as "char" or "string"?
I'm not sure I understand the question. Do you mean from the database? I've only
got an integer in the database, but I could try doing the conversion to
character on the DB side rather than in my code.
You can also try "Encoding.UTF8.GetString(...)".
If you'll get this string then [index] should do the job.


That was one of the permutations I tried. The problem is it expects you to feed
it the Unicode value of the characters in the GetString argument, and I don't
have the Unicode value, that's what I'm trying to get.
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 code.

I've tried several variations of the following but so far none of them have
worked:

byte charCode = // get value from datatable
Encoding.ASCII.GetString( new byte [] { charCode } );

I also tried simply casting the charCode as a char, but of course that results
in a character using the charCode as a Unicode value, which gets me the wrong
character.

I found an example in JScript that does exactly what I want, but I'm writing in
C#. I only bring this up because it shows me that what I want to do is at least
possible, which leads me to believe there must be a way to do it.

Basically, I'm looking for an equivalent to the JScript charCodeAt method:

http://msdn.microsoft.com/library/en...charcodeat.asp

Any suggestions?
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"


---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"
Nov 16 '05 #13
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
>However, the database really ought to be able to know how it's stored
>them and give you the text in Unicode. What's the type of the column,
>what's the database in question, and how are you retrieving the
>database?
The database has stored the value as an integer. The database isn't storing the
character, it's storing the character code (i.e. it's not storing the smart
quote, it's storing 147 as an integer).

The database is SQL Server 2000 and my C# code is calling a stored proc that is
used to populate a DataTable.


So it's storing a character as the integer value in an ill-defined
encoding? That doesn't sound like a terribly good idea, to be honest.


We also have the font set to use to represent the character. This information is
being used to create a Word document using WordML.

It ain't my design, but it has been working pretty well until we went to
implement this new feature.
Anyway, Encoding.Default *might* do what you want it to, as I said
before - just put the integer value into a byte array as the sole
value, and call Encoding.GetString to get the appropriate string. If
the encoding is subtly different though, you'll have problems.


I'll give it a shot. Thanks.
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"
Nov 16 '05 #14
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
>However, the database really ought to be able to know how it's stored
>them and give you the text in Unicode. What's the type of the column,
>what's the database in question, and how are you retrieving the
>database?
The database has stored the value as an integer. The database isn't storing the
character, it's storing the character code (i.e. it's not storing the smart
quote, it's storing 147 as an integer).

The database is SQL Server 2000 and my C# code is calling a stored proc that is
used to populate a DataTable.


So it's storing a character as the integer value in an ill-defined
encoding? That doesn't sound like a terribly good idea, to be honest.


We also have the font set to use to represent the character. This information is
being used to create a Word document using WordML.

It ain't my design, but it has been working pretty well until we went to
implement this new feature.
Anyway, Encoding.Default *might* do what you want it to, as I said
before - just put the integer value into a byte array as the sole
value, and call Encoding.GetString to get the appropriate string. If
the encoding is subtly different though, you'll have problems.


I'll give it a shot. Thanks.
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"
Nov 16 '05 #15
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
Anyway, Encoding.Default *might* do what you want it to, as I said
before - just put the integer value into a byte array as the sole
value, and call Encoding.GetString to get the appropriate string. If
the encoding is subtly different though, you'll have problems.


That did it. Worked like a charm. Thanks.
---
Craig Wagner, craig.wagner(at)comcast.net
Portland, OR

"Don't ban high-performance vehicles, ban low-performance drivers!"
Nov 16 '05 #16

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

Similar topics

1
by: Dominik Jain | last post by:
Hi! We hope somebody can help me with the following: We have a form through which unicode data might be submitted. We need to be able to detect when this happens and, most importantly, we need...
6
by: S. | last post by:
if in my website i am using the sgml { notation, is it accurate to say to my users that the site uses unicode or that it requires unicode? is there a mathematical formula to calculate a unicode...
12
by: Chris Mullins | last post by:
I'm implementing RFC 3491 in .NET, and running into a strange issue. Step 1 of RFC 3491 is performing a set of mappings dicated by tables B.1 and B.2. I'm having trouble with the following...
4
by: Basil | last post by:
Hello. I have compiler BC Builder 6.0. I have an example: #include <strstrea.h> int main () { wchar_t ff = {' s','d ', 'f', 'g', 't'};
11
by: Patrick Van Esch | last post by:
Hello, I have the following problem of principle: in writing HTML pages containing ancient greek, there are two possibilities: one is to write the unicode characters directly (encoded as two...
0
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...
5
by: Sonu | last post by:
Hello everyone and thanks in advance. I have a multilingual application which has been built in MFC VC++ 6.0 (non-Unicode). It support English German Hungarian so far, which has been fine. But...
40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
29
by: Ron Garret | last post by:
>>> u'\xbd' u'\xbd' >>> print _ Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in position 0: ordinal not in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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...
0
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
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
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...

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.