简体   繁体   English

如何在winform程序中以正确的方式输入或输出韩语

[英]How can I Input or output Korean in right way in a winform program

        Console.InputEncoding = Encoding.Unicode;
        Console.OutputEncoding = Encoding.GetEncoding("utf-8");
        Console.WriteLine("开始测试starttest전소미123");
        string input = Console.ReadLine();
        Console.WriteLine(input);
        Console.ReadKey();
        Console.ReadKey();

when I run these codes, I get exactly the same string, as below当我运行这些代码时,我得到完全相同的字符串,如下所示

在此处输入图片说明

And I can't get the right characters if I don't set InputEncoding or OutputEncoding or both.如果我不设置 InputEncoding 或 OutputEncoding 或两者,我将无法获得正确的字符。

But I can't set Console.OutputEncoding in a winform program.但我无法在 winform 程序中设置 Console.OutputEncoding。 It threw An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll.它引发了 mscorlib.dll 中发生类型为“System.IO.IOException”的未处理异常。 This error happened on the second line below,这个错误发生在下面的第二行,

Console.OutputEncoding = Encoding.Unicode;

code代码

        Console.InputEncoding = Encoding.Unicode;
        Console.OutputEncoding = Encoding.Unicode;
        Process process = new Process()
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = $".\\test.exe",
                Arguments = "",
                CreateNoWindow = true,
                UseShellExecute = false,
                ErrorDialog = true,
                //AutoFlush = true,
                //RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                StandardOutputEncoding = Encoding.GetEncoding("utf-8"),
            },
        };
        process.Start();
        string text = process.StandardOutput.ReadLine();

I had searched similar questions online and tested many times for hours, just can't figure it out.我在网上搜索过类似的问题并测试了好几个小时,就是想不通。

What text editor and encoding are you using for the exe file?您对 exe 文件使用什么文本编辑器和编码? I think for example Notepad's default encoder is ANSI which I know do not support Asian symbols.我认为例如记事本的默认编码器是 ANSI,我知道它不支持亚洲符号。 If you want to change the encoder for Notepad click File -> Save as, then you can change the encoding just left to the Save button and change the encoding to UTF-8 or Unicode.如果要更改记事本的编码器,请单击“文件”->“另存为”,然后您可以更改“保存”按钮左侧的编码并将编码更改为 UTF-8 或 Unicode。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM