代码之家  ›  专栏  ›  技术社区  ›  Euxinus

如何在控制台应用程序中使用charmap中的特殊符号?

c#
  •  0
  • Euxinus  · 技术社区  · 3 年前

    我试图输入一个特殊字符,但应用程序仍然显示一条消息:密码错误! 如果有人知道我的错误是什么,如果你指出,我会很高兴的。提前感谢。

    我使用的特殊字符:(U+263A)

    Console.WriteLine("Enter a password:");
    
    var pass = Console.ReadLine();
    
    var key = '\u263a'.ToString();
    
    while (pass != key)
    {
        if (pass != key)
        {
            Console.WriteLine("Wrong password!");
            pass = Console.ReadLine();    
        }
        else
        {
            break;
        }
    }
    Console.WriteLine("Info: test 123");
    
    Console.ReadKey();
    

    upd。 Screenshot 1: variable "pass" in debug

    Screenshot 2: variable "key" in debug

    0 回复  |  直到 3 年前
        1
  •  0
  •   Ledrake    3 年前

    把这个放进去

    Console.InputEncoding = Encoding.GetEncoding(1200);
    

    在节目的顶部

        2
  •  0
  •   Morty Smith    3 年前

    尝试将其解码为 UTF-8

    Console.WriteLine("Enter a password:");
    
    Console.InputEncoding = System.Text.Encoding.UTF8;
    var pass = Console.ReadLine();
    
    var key = '\u263a'.ToString();
    
    while (pass != key)
    {
        if (pass != key)
        {
            Console.WriteLine("Wrong password!");
            Console.InputEncoding = System.Text.Encoding.UTF8;
            pass = Console.ReadLine();    
        }
        else
        {
            break;
        }
    }
    Console.WriteLine("Info: test 123");
    
    Console.ReadKey();