LoginSignup
16
13

More than 5 years have passed since last update.

C#で、文字コードを表す文字列から、文字に変換する

Posted at

定数ではなく変数で扱いたい場合に若干調べるのに時間がかかったのでメモ。

"304C" -> "が" のように、
Unicode文字コードを表す文字列から文字に変換したい場合、
Convert クラスを使用します。

sample.cs
string charCode = "304C";
int charCode16 = Convert.ToInt32(charCode,16);  // 16進数文字列 -> 数値
char c = Convert.ToChar(charCode16);  // 数値(文字コード) -> 文字
string newChar = c.ToString();    // "が" という「文字列」

参考

16
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
13