I just have a small issue with a Visual Basic (2010 Express) .NET application I'm making. It's a console-based application and I want it to print superscript numbers.
Well, I've found out the superscript numbers from Charmap and my code is this:
Public Module MainModule
Public Sub Main()
Console.Write(GetExponentialNumAsStr(12345, 12345)) 'This must be printed as 12345¹²³⁴⁵
Console.ReadKey(True)
End Sub
Public Function GetExponentialNumAsStr$(Number As Double, Exponent%)
If Exponent = 1 Then Return Number : Exit Function
Return Number.ToString & Exponent.ToString.Replace("-", "⁻").Replace("0", "⁰").Replace("1", "¹").Replace("2", "²").Replace("3", "³").Replace("4", "⁴").Replace("5", "⁵").Replace("6", "⁶").Replace("7", "⁷").Replace("8", "⁸").Replace("9", "⁹")
End Function
End Module
Okay, the GetExponentialNumAsString$
function works well and gives 12345¹²³⁴⁵, which is okay (checked through Immediate window
), but the only problem is that while printing the same in the Console view gives this:
123451²345
Why is it that only 2 is shown in superscript form and why not the other digits also?
If I try printing 0 to 9 as superscript, it comes like this:
1²345678?°
Well 9 is gone, but the other digits is what confusing me. Only 2 and 0 are shown in superscript form!
Command Prompt
window... this is what came:ECHO ¹²³⁴⁵⁶⁷⁸⁹⁰>Hello123.TXT
and what came was the same thing as above. So... has no use.Thanks to Hans Passant's comment, the trick is to set the Console's output encoding to UTF-8, such as
Console.OutputEncoding = System.Text.Encoding.UTF8