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.
Related
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³
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.
I have a problem when inserting a string to database due to some encoding issues.
String source is a external rss feed.
In web browser it looks ok. Even in debugger the text appears to be ok.
If I copy the strong to notedpad, the result is also ok.
But in notepad++ was possible to see that string is using combining characters.
If changing to ansii, both combined appears.
e.g.
á is displayed as a´
(In notepad++ is is like having two chars, on over the other. I even can select ... half of the char)
I googled a lot and tried very different approach to this problem.
I really want to find a clever way of convert string with combining diacritics to simple utf8 database compatible ones.
Any help?
Thank you so much!
This should work for you
output.Normalize(NormalizationForm.FormC)
This little test gave 3, 2, 3. The middle string is correctly combining A and it's diacritic into a single UTF-8 character
Console.WriteLine(Encoding.UTF8.GetByteCount(("A\u0302")));
Console.WriteLine(Encoding.UTF8.GetByteCount(("A\u0302").Normalize(NormalizationForm.FormC)));
Console.WriteLine(Encoding.UTF8.GetByteCount(("T\u0302").Normalize(NormalizationForm.FormC)));
My Mac can solve this running the following Command in Terminal:
iconv -f utf-8-mac -t utf-8 inputfile >outputfile
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';
I am working with a project that includes getting MMS from a mms-gateway and storing the image on disk.
This includes using a received base64encoded string and storing it as a zip to a web server. This zip is then opened, and the image is retrieved.
We have managed to store it as a zip file, but it is corrupted and cannot be opened.
The documentation from the gateway is pretty sparse, and we have only a php example to rely on. I think we have figured out how to "translate" most of it, except for the PHP function stripcslashes(inputvalue). Can anyone shed shed any light on how to do the same thing in c#?
We are thankful for any help!
stripcslashes() looks for "\x" type elements within longer strings (where 'x' could be any character, or perhaps, more than one). If the 'x' is not recognised as meaningful, it just removes the '\' but if it does recognise it as a valid C-style escape sequence (i.e. "\n" is newline; "\t" is tab, etc.), as I understand it, the recognised character is inserted instead: \t will be replaced by a tab character (0x09, I think) in your string.
I'm not aware of any simple way to get the .net framework to do the same thing without building a similar function yourself. This obviously isn't very hard, but you need to know which escape sequences to process.
If you happen to know (or find out by inspecting your base64 text) that the only thing in your input that will need processing is a particular one or two sequences (say, tab characters), it becomes very easy and the following snippet shows use of String.Replace():
string input = #"Some\thing"; // '#' means string stored without processing '\t'
Console.WriteLine(input);
string output = input.Replace(#"\t", "\t");
Console.WriteLine(output);
Of course, if you really do simply want to remove all the slashes:
string output = input.Replace(#"\", "");