簡體   English   中英

將十六進制字符串轉換回char

[英]Converting hex string back to char

我知道 - 關於這一點有很多主題,但即使我看了很多他們無法找到解決方案..我正在將char轉換為十六進制,如下所示:

char c = i;
int unicode = c;
string hex = string.Format("0x{0:x4}", unicode);

問題:如何將十六進制轉換為char?

你可以嘗試:

hex = hex.Substring(2); // To remove leading 0x
int num = int.Parse(hex, NumberStyles.AllowHexSpecifier);
char cnum = (char)num;
using System;
using System.Globalization;

class Sample {
    static void Main(){
        char c = 'あ';
        int unicode = c;
        string hex = string.Format("0x{0:x4}", unicode);
        Console.WriteLine(hex);
        unicode = int.Parse(hex.Substring(2), NumberStyles.HexNumber);
        c = (char)unicode;
        Console.WriteLine(c);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM