Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
can someone tell me how to write meter squared in console application c#
Posted
Comments
Sergey Alexandrovich Kryukov 2-Dec-12 20:06pm    
Come to think about, that was a good question of considerable practical meaning.
Many don't know about the possibility of using Unicode in standard consoles.
So, I voted 5 for the question.
--SA

First, you need to enable Unicode for console:
C#
System.Console.OutputEncoding = System.Text.Encoding.UTF8;
System.Console.WriteLine("m²");


For "", "square" character is the Unicode code point U+00B2. So, the second line could also be written as:
C#
System.Console.WriteLine("m\u00b2");


Remember that even though .NET supports all the encodings implemented as descendants of System.Text.Encoding, console may not support them all. Before answering, I made sure that at least UTF-8 and ASCII work (but ASCII will not show most Unicode characters, of course).

Please see:
http://msdn.microsoft.com/en-us/library/system.console.aspx[^],
http://msdn.microsoft.com/en-us/library/system.console.outputencoding.aspx[^].

—SA
 
Share this answer
 
v5
Comments
__TR__ 2-Dec-12 13:24pm    
My 5!
Sergey Alexandrovich Kryukov 2-Dec-12 14:40pm    
Thank you.
--SA
The Ascii character id for the superscript 2 (small 2) which appears in M2 (meter's squared) is CHR(253)

Wether your application would display it correctly or not would depend on the font and if the font contains the letter.

The font also relies on the codepage too and i expect a console app relies on the codepage.

Because the code 253 is greater than 128 that means it is an EXTENDED character (not part of the original 128 characters used in 8bit fonts) and extended characters may not always display correctly.

Wherever your using it you can always try replacing the the small 2 character/symbol with the following -> CHR(253)

Alternatively try to find which font is being used by your console app and if its possible to change it, i say this because i'm not sure if console app fonts can be changed.

If it works it works and if not your back at square one.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Dec-12 0:21am    
"Extended characters" are not in use for a century! A long time ago, all systems support either Unicode or regular ASCII, but never "extended". The problem cannot be resolved by changing just the point even following your own logic. The solution is to enable Unicode on console.

It's not good to provide "answer" which you did not test by yourself. I tested it -- please see my solution.

Sorry, but the vote of 1 is well deserved.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900