I want to display superscript 3 in console application. I've tried the following methods but none of them works.
Console.WriteLine("\xB3");
(from here)
Console.WriteLine("³"); // Copied from charmap.exe and also from Wikipedia
How can I display it?
You need to make sure that the encoding of your console is appropriate for rendering the character that you are trying to output.
The relevant property is Console.OutputEncoding.
See MSDN: Console.OutputEncoding Property
0xB3 is a superscript 3 in Unicode, so you need to select UnicodeEncoding.
See MSDN: UnicodeEncoding Class
This works for me:
Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.Write("2\xB3");
Output:
2³
Related
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.Unicode.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.
Just a quick question. For the roman numerals above 3999, we used to represent them using a overline. For representing 4000, we will be using the following:
So, to display this overline, what should I do? Also, please advice me which of the above is right?
Update #1
I saw somewhere that we can use Unicode Characters by using the following code:
Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.WriteLine("H\u0305");
Console.WriteLine("\u0305H");
Console.ReadLine();
After putting this code, I have set my console to use Consolas font at 14pt. I got this output:
I was expecting either of the code to show me a combined version, but no avail.
In the console? You can't. Drawing to the console in such a manner is not possible as the console only supports characters.
One does exist in Unicode (as seen here) but this is merely an overlined space.
Am working on Universal Windows application and am reading string and if the string contains smiley characters (For eg. 😕) its not getting displayed.
But when I try to declare it statically, Like
<TextBlock Text="😊" />
Am getting the smiley in my emulator, also when my emulator is running. But when I try to work this out via C#, am getting the value as it is. I can't see the smiley here. Like this,
textBlock.Text = "😊";
Do I need to change any textblock properties so that I may get the smileys?
I would recommend you to have a look at http://www.charbase.com/block/emoticons which provides a good overview of emoticons in unicode. Java and .NET seem to use the same escape mechanisms.
In the case of your smiley \ud83d\ude0a would probably do the trick. Your original format 😊 is html-escaped, not .NET escaped.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Which passwordchar shows a black dot (•) in a winforms textbox?
Unicode encoding for string literals in C++11
I want to use code to reveal the password or make it a dot like •
textBoxNewPassword.PasswordChar = (char)0149;
How can I achieve this?
http://blog.billsdon.com/2011/04/dot-password-character-c/ suggests '\u25CF';
Or try copy pasting this •
(not exactly an answer to your question, but still)
You can also use the UseSystemPasswordChar property to select the default password character of the system:
textBoxNewPassword.UseSystemPasswordChar = true;
Often mapped to the dot, and always creating a consistent user experience.
You need to look into using the PasswordBox control and setting the PasswordChar as *.
Example:
textBox1.PasswordChar = '*'; // Set a text box for password input
Wikipedia has a table of similar symbols.
In C#, to make a char literal corresponding to U+2022 (for example) use '\u2022'. (It's also fine to cast an integer literal as you do in your question, (char)8226)
Late addition. The reason why your original approach was unsuccessful, is that the value 149 you had is not a Unicode code point. Instead it comes from Windows-1252, and Windows-1252 is not a subset of Unicode. In Unicode, decimal 149 means the C1 control code "Message Waiting".
You could translate from Windows-1252 with:
textBoxNewPassword.PasswordChar =
Encoding.GetEncoding("Windows-1252").GetString(new byte[] { 149, })[0];
but it is easier to use the Unicode value directly of course.
In newer versions of .NET, you need to call:
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
before you can use something like Encoding.GetEncoding("Windows-1252").
textBoxNewPassword.PasswordChar = '\u25CF';
How can I output Windows Alt key codes to the console in a C# console app using Console.WriteLine()?
I would like to output characters such as those used for creating boxes.
I can do so manually in a command prompt by holding alt and typing in the appropriate number such as Alt+205, Alt+187, etc.
Thanks
I suppose the easiest way would be to include them directly in your string literals within your source code:
Console.WriteLine("═╗");
EDIT: I'm sorry - my answer is incorrect. ASCII.GetChars will not work for extended ASCII characters. Thanks to Douglas for correcting me.
I think Douglas's answer is the most direct, but you could also get the character based on the value directly using something like this:
char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[]
{65});
For whatever ASCII code you wanted.