开发者

Outputting a Unicode character in C#

I'm new to programming and self taught. I'm trying to output the astrological symbol for Taurus, which is supposed to be U+2649 in Unicode. Here is the code I'm using...

string myString = "\u2649";
byte[] unicode = System.Text.Encoding.Unicod开发者_C百科e.GetBytes(myString);
Console.WriteLine(unicode.Length);

The result I'm getting is the number 2 instead of the symbol or font. I'm sure I'm doing something wrong.


Why are you converting it to unicode, this will not do anything.. lose the conversion and do the following:

string a ="\u2649"  ; 

Console.write(a) ; 


You need to have a font which displays that glyph. If you do, then:

Console.WriteLine(myString); 

is all you need.

EDIT: Note, the only font I could find which has this glyph is "MS Reference Sans Serif".


The length of the Unicode character, in bytes, is 2 and you are writing the Length to the Console.

Console.WriteLine(unicode.Length);

If you want to display the actual character, then you want:

Console.WriteLine(myString); 

You must be using a font that has that Unicode range for it to display properly.

UPDATE:

Using default console font the above Console.WriteLine(myString) will output a ? character as there is no \u2649. As far I have so far googled, there is no easy way to make the console display Unicode characters that are not already part of the system code pages or the font you choose for the console.

It may be possible to change the font used by the console: Changing Console Fonts


You are outputting the length of the character, in bytes. The Console doesn't support unicode output, however, so it will come out as an '?' character.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜