从字符代码中获取Unicode值? [英] Obtain Unicode value from Character Code?

查看:49
本文介绍了从字符代码中获取Unicode值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我在

数据库中存储了一系列字符代码。在某些情况下,它们是角色的ASCII值,在其他

的情况下,它们是>与您一起使用的127个字符代码值

用于在文档中输入特殊字符的ALT键(例如ALT + 0147和

ALT + 0148让您变得聪明引号'')。


我正在试图弄清楚如何(或者是否可能)获得相当于的Unicode

字符代码。


我已经尝试了以下几种变体,但到目前为止,没有一种具有

工作:


byte charCode = //从datatable获取值

Encoding.ASCII.GetString(new byte [] {charCode});


我也是尝试简单地将charCode转换为char,但当然这会导致使用charCode作为Unicode值的字符中的
,这会让我错误的

字符。 />

我在JScript中找到了一个完全符合我想要的例子,但我写的是

C#。我只是提起这件事,因为它告诉我,我想做的事情至少是可能的,这让我相信必须有办法做到这一点。


基本上,我正在寻找与JScript charCodeAt方法等效的方法:

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


有什么建议吗?

---

Craig Wagner,craig.wagner(at)comcast.net

波特兰,俄勒冈州/>

不要禁止高性能车辆,禁止低性能驾驶员!

解决方案

嗨克雷格,


你没有尝试将char码作为char或者字符串?


您也可以尝试Encoding.UTF8.GetString(...)。

如果你愿意的话得到这个字符串然后[索引]应该做的工作。


问候


Marcin

我有一种情况,我在
数据库中存储了一系列字符代码。在某些情况下,它们是角色的ASCII值,在其他情况下,它们是> 127个字符代码值,与ALT键结合使用,可以在文档中输入特殊字符(例如ALT + 0147和
ALT + 0148可以获得智能引号)。

我正在试图弄清楚(或者是否可能)获得与字符代码相当的Unicode。

我试过了以下几种变体,但到目前为止,它们都没有工作:

字节charCode = //从数据表中获取值
Encoding.ASCII.GetString(new byte [] { charCode});

我也试过简单地将charCode转换为char,但当然这会在使用charCode作为Unicode值的字符中产生
,这会让我错误

我在JScript中找到了一个完全符合我想要的例子,但我正在用C#编写。我只是提起这件事,因为它告诉我,我想做的事情至少是可能的,这让我相信必须有办法去做。

基本上,我我正在寻找JScript charCodeAt方法的等价物:

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

有什么建议吗?
- -
Craig Wagner,craig.wagner(at)comcast.net
波特兰,或者

不要禁止高性能车辆,禁止低性能车手!



嗨克雷格,


你没有尝试将这些字符代码作为炭"或者字符串?


您也可以尝试Encoding.UTF8.GetString(...)。

如果你愿意的话得到这个字符串然后[索引]应该做的工作。


问候


Marcin

我有一种情况,我在
数据库中存储了一系列字符代码。在某些情况下,它们是角色的ASCII值,在其他情况下,它们是> 127个字符代码值,与ALT键结合使用,可以在文档中输入特殊字符(例如ALT + 0147和
ALT + 0148可以获得智能引号)。

我正在试图弄清楚(或者是否可能)获得与字符代码相当的Unicode。

我试过了以下几种变体,但到目前为止,它们都没有工作:

字节charCode = //从数据表中获取值
Encoding.ASCII.GetString(new byte [] { charCode});

我也试过简单地将charCode转换为char,但当然这会在使用charCode作为Unicode值的字符中产生
,这会让我错误

我在JScript中找到了一个完全符合我想要的例子,但我正在用C#编写。我只是提起这件事,因为它告诉我,我想做的事情至少是可能的,这让我相信必须有办法去做。

基本上,我我正在寻找JScript charCodeAt方法的等价物:

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

有什么建议吗?
- -
Craig Wagner,craig.wagner(at)comcast.net
波特兰,或者

不要禁止高性能车辆,禁止低性能车手! "



Craig Wagner< cr ************ @ hotmail.com>写道:

我有一种情况,我在
数据库中存储了一系列字符代码。在某些情况下,它们是角色的ASCII值,在其他情况下,它们是> 127个字符代码值,与ALT键组合使用,可以在文档中输入特殊字符(例如ALT + 0147和
ALT + 0148可以获得智能引号'')。


< snip>

有什么建议吗?




我想*你''在Encoding.Default之后重新开始。


然而,数据库真的应该能够知道它是如何存储的,并且它们会给你带来文本。 Unicode格式。列的类型是什么,

有问题的数据库是什么,以及如何检索

数据库?

-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件。 />


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!"

解决方案

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!"



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!"



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


这篇关于从字符代码中获取Unicode值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆