Results 1 to 11 of 11

Thread: ∞ in console with Server 2019?

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    ∞ in console with Server 2019?

    Ok ... so in a command prompt:
    Code:
    c:\>echo ∞
    ∞
    ...as expected in both Windows 10 and Server 2019

    but for some reason when I go (and enter "∞" for the readline):
    VB.Net Code:
    1. Dim Data = Console.ReadLine()
    2. Console.WriteLine(Data)
    3. Console.WriteLine("∞")
    Data gets set to 8, and both output lines in the console read "8"!

    This however does not appear to happen on Windows 10, but does on Server 2019!

    Any ideas?

  2. #2
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: ∞ in console with Server 2019?

    Looks like an issue with the text Encoding. '8' is typically the fallback character used by encodings that don't support the '∞' character, but do support fallback.

    Try setting the Console.OutputEncoding and probably also the Console.InputEncoding to UTF-8 or UTF-16. I've found UTF-16 to be more reliable; UTF-8 can be a bit quirky, but I'm usually on Windows 7 with .NET Framework 4.6 so YMMV.

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ∞ in console with Server 2019?

    Quote Originally Posted by i00 View Post
    Ok ... so in a command prompt:
    Code:
    c:\>echo ∞
    ∞
    ...as expected in both Windows 10 and Server 2019

    but for some reason when I go (and enter "∞" for the readline):
    VB.Net Code:
    1. Dim Data = Console.ReadLine()
    2. Console.WriteLine(Data)
    3. Console.WriteLine("∞")
    Data gets set to 8, and both output lines in the console read "8"!

    This however does not appear to happen on Windows 10, but does on Server 2019!

    Any ideas?
    So I created a Console application with this
    Code:
            Console.WriteLine("∞")
    and the output was correct.

    The encoding for both Out and In is

    System.Text.SBCSCodePageEncoding
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: ∞ in console with Server 2019?

    Yeah, several of the single byte encodings have the '∞' character, but many don't.

    The 'en-US' culture defaults to Encoding IBM437 for the console, and that has a mapping for '∞'. However 'en-GB' defaults to IBM850 which doesn't have it. I think i00 is from the UK, so that may be the root of the problem.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: ∞ in console with Server 2019?

    Quote Originally Posted by Inferrd View Post
    I think i00 is from the UK, so that may be the root of the problem.
    So racist!

  6. #6

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: ∞ in console with Server 2019?

    Quote Originally Posted by Inferrd View Post
    I think i00 is from the UK, so that may be the root of the problem.
    I am actually in Australia ... so all 8's and ∞'s are always written upside down here :P ...

    Server 2019:
    {System.Text.SBCSCodePageEncoding}
    BodyName: "ibm850"
    CodePage: 850
    DecoderFallback: {System.Text.InternalDecoderBestFitFallback}
    EncoderFallback: {System.Text.InternalEncoderBestFitFallback}
    EncodingName: "Western European (DOS)"
    HeaderName: "ibm850"

    Windows 10:
    {System.Text.SBCSCodePageEncoding}
    BodyName: "IBM437"
    CodePage: 437
    DecoderFallback: {System.Text.InternalDecoderBestFitFallback}
    EncoderFallback: {System.Text.InternalEncoderBestFitFallback}
    EncodingName: "OEM United States"
    HeaderName: "IBM437"

    Both systems region options appear to be the same??
    What should I do to make this support the infinity symbol correctly (also I don't want to change something only to break something else)?

    Thanks

    EDIT:
    I have set it to:
    VB.Net Code:
    1. Console.InputEncoding = System.Text.Encoding.Unicode
    2. Console.OutputEncoding = System.Text.Encoding.Unicode
    Assume that this won't break anything?

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: ∞ in console with Server 2019?

    Quote Originally Posted by i00 View Post
    I am actually in Australia
    You put the queen on your money, you're British.

    Quote Originally Posted by i00 View Post
    EDIT:
    I have set it to:
    I think you should be fine with that.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  8. #8

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: ∞ in console with Server 2019?

    Quote Originally Posted by dday9 View Post
    I think you should be fine with that.
    Ok...
    It seemed to be at first glance ... but now when entering > 126 chrs with Console.ReadLine I need to press enter 2x to get it to register?

    Also Console.BufferWidth = 120 ... so probably isn't to do with that

    Any ideas?

  9. #9
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: ∞ in console with Server 2019?

    Sorry for the delay in replying. Just back from mandatory cultural sensitivity training

    According to the documentation for the Console.ReadLine Method, there's a 256 character limit to the size of the standard input buffer, and that includes the NewLine character(s):
    By default, the method reads input from a 256-character input buffer. Because this includes the Environment.NewLine character(s), the method can read lines that contain up to 254 characters. To read longer lines, call the OpenStandardInput(Int32) method.
    For some weird reason, when using UTF-16 (which is a fixed width, 2 byte encoding), that translates to 256 bytes, not Chars. So your 127 chrs plus the NewLine would take up the 256 bytes (each UTF-16 Char takes 2 bytes to represent it). Seems odd though. Maybe it's using UTF-32 internally or something. Don't know.

    So following the advice in the docs above, you could try something like:
    Code:
    Sub Main()
        Console.InputEncoding = Text.Encoding.Unicode
        Console.OutputEncoding = Text.Encoding.Unicode
    
    
        Dim strm = Console.OpenStandardInput(0)
        Dim reader = New IO.StreamReader(strm, Text.Encoding.Unicode)
        Console.SetIn(reader)
    
        Console.WriteLine("enter x to exit")
        Console.WriteLine()
    
        Dim input As String
        Do       
            input = Console.In.ReadLine()
    
            Console.WriteLine()
            Console.WriteLine($"echo> {input}")
            Console.WriteLine()
    
        Loop Until input = "x"
    
    
    End Sub
    which calls Console.OpenStandardInput to open an input Stream, points the input reader to that Stream with Console.SetIn, and replaces all calls to Console.Readline() with calls to Console.In.ReadLine() instead.

    That said, I've not been able to enter more than 512 UTF-16 Chars including NewLine using this approach. Hopefully you don't need to??

  10. #10
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: ∞ in console with Server 2019?

    Quote Originally Posted by Inferrd View Post
    That said, I've not been able to enter more than 512 UTF-16 Chars including NewLine using this approach. Hopefully you don't need to??
    After a little more thought, I remembered there's an overload of the StreamReader constructor that accepts a buffer size, and sure enough, specifying a larger buffer size allows more characters to be typed at the keyboard. The buffer size is given as the number of Bytes, so for UTF-16 (what Microsoft name as 'Unicode' in their encoding schemes) you'd need to specify twice as many bytes as the number of characters you are likely to require ('Unicode' encoding is a two byte encoding).

    This would also explain why you were only able to enter 127 'Unicode' characters even though Microsoft talk about a 256-character input buffer: they are thinking of single byte characters, which is the default for the Console, no doubt for historical reasons.

    So in the code in my previous post, you'd create the StreamReader along the lines of:
    Code:
    Dim characterBufferSize = 8192
    Dim reader = New IO.StreamReader(strm, Text.Encoding.Unicode, True, characterBufferSize * 2)
    Console.SetIn(reader)

  11. #11

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: ∞ in console with Server 2019?

    Nice; thanks for that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width