Search code examples
vb.netconsole-applicationsuperscript

VB 2010: Console application prints some superscript number characters as normal



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!


I also tried copy-pasting all the superscript numbers in a Command Prompt window... this is what came:
Command Prompt's display of ¹²³⁴⁵⁶⁷⁸⁹⁰
Command Prompt, in fact, when copy-pasted, shows correctly!

So what should I do? Convert those superscript numbers to CP-437 (DOS) encoding and then display it?
Please help me! Thank you everybody!
EDIT: I've tried saving that thing as a file in my Desktop using CP-437 encoding. What appears is like 1ý345678?ø. And when converted back manually to UTF-8 or one of the general encodings, it comes back as 1²345678?°.
Also tried using ECHO ¹²³⁴⁵⁶⁷⁸⁹⁰>Hello123.TXT and what came was the same thing as above. So... has no use.
And I am a bit sure that CP-437 has those superscript characters because Command Prompt can display them!!!


Solution

  • 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
    

    And look! It comes!

    Resulting output using UTF-8 encoding