C# Hexadecimal to char

后端 未结 4 1238
Happy的楠姐
Happy的楠姐 2020-12-06 17:33

I have a hexidecimal string with a length of 4, such as \"003a\".

What is the best way to convert this into a char? First convert to bytes and then to char?

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 18:09

    In 2020 I'd do it like this

    char c = (char)0x3A;
    

    If I needed it to be a string for use in removing a non-printable character, it would be like this

    s = s.Replace($"{(char)0x3A}", ""));
    

提交回复
热议问题