【问题标题】:Convert a get a character's unicode(?) value? [closed]转换获取字符的 unicode(?) 值? [关闭]
【发布时间】:2012-10-17 23:52:24
【问题描述】:

我需要将 char 转换为 int 并返回。

这是我用来将 char 转换为 int 的方法:

(char)65 // Returns 'a'

这是我试图用来将其转换回来的内容:

(int)'a' // Returns 97

任何想法我能做什么?

【问题讨论】:

  • (char)65 应该返回 'A' 而不是 'a', asciitable.com
  • 我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
  • 为什么需要这种转换?大多数情况下,最好使用 Encoding 将特定编码编码/解码为另一种编码,而不必知道(或担心)CLR 使用的本机编码。

标签: c# unicode converter


【解决方案1】:

试试这个,

char x = 'a';
int y = (int)x;

【讨论】:

  • a = 97,而A = 65
  • 哇,我不敢相信我把它搞砸了。哎呀,谢谢。
【解决方案2】:

65 是大写字母“A”的字符代码。 97 是小写的“a”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多