This question already has answers here:
How to write Unicode characters to the console?
(5 answers)
Closed 9 years ago.
I tried to print this character ’ using Console.WriteLine((char) 146); but it printed ?. When I set Console.OutputEncoding = System.Text.Encoding.UTF8 it printed some glitched characters, not the one I needed.
The code you need is 8217.
But you also have to enable UTF8 encoding and change font, to the one which can display UTF8 characters:
Console.OutputEncoding = Encoding.UTF8;
int value = '’';
Console.WriteLine((char)value);
Console.ReadLine();
And if your current console font doesnt support this character you may also have to change it.
How?
After you launch the console right-click on the title bar -> properties -> fonts -> Lucida Console
And voila it works!
Have you tried this?
static void Main(string[] args)
{
Console.WriteLine((char)39);
}
At least this works for me.
Related
This question already has answers here:
How to insert a Symbol (Pound, Euro, Copyright) into a Textbox
(2 answers)
Closed 2 years ago.
I want to display the String with superscript like Shibu® using C#.
Unicode of ®:- U+000AE
Here is the code:-
String s = "Shibu";
Console.write(s.join("\xBU+000AE", s));
I am not getting proper output like Shibu®.
You need to concatenate those strings, string.Join is for joining several strings together with a special one repeated in between.
Also, representation of unicode characters is done with \uXXXX where XXXX is the hexadecimal code point value.
string s = "Shibu";
Console.WriteLine(s + "\u00AE");
Or simply
string s = "Shibu\u00AE";
Console.WriteLine(s);
Also, you can directly write unicode characters; C# strings are unicode.
string s = "Shibu®";
Console.WriteLine(s);
This does not, however, set the character as "superscript" in the unicode or font meaning of term. I'm not sure that is possible with native C# strings, you need to cope with the existing basic unicode characters.
For fancier, use a visual rich textbox control, or a WPF control, that allow you to set font options.
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³
This question already has answers here:
How to write Unicode characters to the console?
(5 answers)
Closed 6 years ago.
Background:
I have a table in SQL database, two of the columns are English names and Simplified Chinese names.
With C#, I had records of this table displayed as buttons with both names, such as: Car车. This is how I did it:
button.Text = x.EnglishName + x.ChineseName; The buttons displays correctly.
3.I would like to compare button.Text to other strings, like so:
for (int K = 0; K < alist.Count; K++)
{
string alpha = alist.[K];
if (alpha == button.Text)
//blahblahblah
}
Problem:
There is always an error.
And I found out why: when I use Console.Writeline(button.Text), the output is Car?.
Each Chinese character is turned into a "?"
So, apparently, writing Chinese characters onto the face of a button is fine. But when reading Chinese characters off the face of a button does not work.
How do I correct this?
You might need to change the Encoding type -
Console.OutputEncoding = Encoding.Unicode // For UTF-16
See here for other encoding types available.
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.
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';