如何写单code字符安慰?字符、如何写、code

由网友(姑苏烟雨泪涟痕)分享简介:我在想,如果有可能,在控制台应用程序,写喜欢用.NET℃字?当我尝试写这个人物,控制台输出一个问号。I was wondering if it was possible, in a console application, to write characters like "℃" using .NET? When I...

我在想,如果有可能,在控制台应用程序,写喜欢用.NET℃字?当我尝试写这个人物,控制台输出一个问号。

I was wondering if it was possible, in a console application, to write characters like "℃" using .NET? When I try to write this character, the console outputs a question mark.

这是我的第一篇文章,所以如果我错过了什么,请告诉我。 先谢谢了。

This is my first post, so if I've missed anything, please tell me. Thanks in advance.

推荐答案

这可能是因为你的输出编码设置为ASCII。 尝试使用这个(MSDN链接)发送输出前:

It's likely that your output encoding is set to ASCII. Try using this (MSDN link) before sending output:

Console.OutputEncoding = System.Text.Encoding.Unicode

和这里有一个小的控制台测试应用程序,你可能会发现方便:

and here's a little console test app you may find handy:

C#

using System;
using System.Text;

public static class MyClass {
    public static void Main() {
        Console.OutputEncoding = System.Text.Encoding.UTF8;
        for (var i = 0; i <= 1000; i++) {
            Console.Write(Strings.ChrW(i));
            if (i % 50 == 0) { // break every 50 chars
                Console.WriteLine();
            }
        }
        Console.ReadKey();
    }
}

VB.NET

imports Microsoft.VisualBasic
imports System

public module MyModule
    Sub Main()
        Console.OutputEncoding = System.Text.Encoding.UTF8
        dim i as integer
        for i = 0 to 1000
            Console.Write(ChrW(i))
            if i mod 50 = 0 'break every 50 chars 
                Console.WriteLine()
            end if
        next
    Console.ReadKey()
    End Sub
end module

这也有可能是你选择控制台的字体不支持该特定字符。点击Windows工具栏菜单(图标如C :.),选择属性 - >字体。尝试一些其他字体,看看他们是否正确显示你的性格:

It's also possible that your choice of Console font does not support that particular character. Click on the Windows Toolbar Menu (icon like C:.) and select Properties -> Font. Try some other fonts to see if they display your character properly:

阅读全文

相关推荐

最新文章