• <bdo id='Vk1Ei'></bdo><ul id='Vk1Ei'></ul>

    <small id='Vk1Ei'></small><noframes id='Vk1Ei'>

  • <i id='Vk1Ei'><tr id='Vk1Ei'><dt id='Vk1Ei'><q id='Vk1Ei'><span id='Vk1Ei'><b id='Vk1Ei'><form id='Vk1Ei'><ins id='Vk1Ei'></ins><ul id='Vk1Ei'></ul><sub id='Vk1Ei'></sub></form><legend id='Vk1Ei'></legend><bdo id='Vk1Ei'><pre id='Vk1Ei'><center id='Vk1Ei'></center></pre></bdo></b><th id='Vk1Ei'></th></span></q></dt></tr></i><div id='Vk1Ei'><tfoot id='Vk1Ei'></tfoot><dl id='Vk1Ei'><fieldset id='Vk1Ei'></fieldset></dl></div>

    <legend id='Vk1Ei'><style id='Vk1Ei'><dir id='Vk1Ei'><q id='Vk1Ei'></q></dir></style></legend>

      1. <tfoot id='Vk1Ei'></tfoot>
      2. C# 将字符串转换为字符 - Unicode

        时间:2023-05-20
      3. <legend id='CDRCz'><style id='CDRCz'><dir id='CDRCz'><q id='CDRCz'></q></dir></style></legend>
          • <bdo id='CDRCz'></bdo><ul id='CDRCz'></ul>

                <tbody id='CDRCz'></tbody>
            • <small id='CDRCz'></small><noframes id='CDRCz'>

              <i id='CDRCz'><tr id='CDRCz'><dt id='CDRCz'><q id='CDRCz'><span id='CDRCz'><b id='CDRCz'><form id='CDRCz'><ins id='CDRCz'></ins><ul id='CDRCz'></ul><sub id='CDRCz'></sub></form><legend id='CDRCz'></legend><bdo id='CDRCz'><pre id='CDRCz'><center id='CDRCz'></center></pre></bdo></b><th id='CDRCz'></th></span></q></dt></tr></i><div id='CDRCz'><tfoot id='CDRCz'></tfoot><dl id='CDRCz'><fieldset id='CDRCz'></fieldset></dl></div>
                <tfoot id='CDRCz'></tfoot>

                  本文介绍了C# 将字符串转换为字符 - Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  看看这段代码:

                  string s = "0x00A5";
                  Console.WriteLine(((char)s).ToString()); //Error
                  Console.WriteLine(((char)0x00A5).ToString());
                  

                  我知道为什么会出现错误,但我不知道如何解决这个问题.

                  I know why there is an error but i have no Idea how to solve this.

                  有什么建议吗?

                  string stringHex = "7A";
                  int intFromHex = int.Parse(stringHex , System.Globalization.NumberStyles.HexNumber) + 30;
                  string hex = intFromHex.ToString("X");
                  switch(hex.Length)
                  {
                      case 2:
                          hex = "0x00" + hex;
                          break;
                      case 3:
                          hex = "0x0" + hex;
                          break;
                      case 4:
                          hex = "0x" + hex;
                          break;
                  }
                  char c = (char)hex;
                  string s = "0x00A5";
                  Console.WriteLine(((char)s).ToString());
                  Console.WriteLine(((char)0x00A5).ToString());
                  

                  这是整个代码.我试图用随机的 unicode 字符生成一个字符串.

                  This is the whole Code. Im trying to generate a string with random unicode Chars.

                  推荐答案

                  如果你只想转换一个符号,把Convert:

                  If you want to convert just one symbol, put Convert:

                    string s = "0x00A5";
                  
                    // 
                    string result = ((char)Convert.ToInt32(s, 16)).ToString();
                  

                  如果你想转换几个你必须用正则表达式提取它们:

                  If you want to convert several ones you have to extract them with regular expressions:

                    string s = "0x00A50x00200x0048";
                  
                    //  H
                    string result = Regex.Replace(s, "0x[0-9A-Fa-f]{4}", 
                      match => ((char)Convert.ToInt32(match.Value, 16)).ToString());
                  

                  这篇关于C# 将字符串转换为字符 - Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PInvoke 和字符** 下一篇:如何使用 LINQ 从字符串中删除字符

                  相关文章

                    <tfoot id='P2J8h'></tfoot>
                  1. <i id='P2J8h'><tr id='P2J8h'><dt id='P2J8h'><q id='P2J8h'><span id='P2J8h'><b id='P2J8h'><form id='P2J8h'><ins id='P2J8h'></ins><ul id='P2J8h'></ul><sub id='P2J8h'></sub></form><legend id='P2J8h'></legend><bdo id='P2J8h'><pre id='P2J8h'><center id='P2J8h'></center></pre></bdo></b><th id='P2J8h'></th></span></q></dt></tr></i><div id='P2J8h'><tfoot id='P2J8h'></tfoot><dl id='P2J8h'><fieldset id='P2J8h'></fieldset></dl></div>
                      <bdo id='P2J8h'></bdo><ul id='P2J8h'></ul>

                    1. <small id='P2J8h'></small><noframes id='P2J8h'>

                    2. <legend id='P2J8h'><style id='P2J8h'><dir id='P2J8h'><q id='P2J8h'></q></dir></style></legend>