locked
How to print all members of a Character Set? RRS feed

  • Question

  • I am wondering how to enumerate and print all members of EACH installed character set in Windows?

    Here is the code I have so far which - pulls out each Encoding and then tries to print chars from 0..200. I could not figure out how to enumerate its members. Here is my code so far.

    ([Text.Encoding]::GetEncodings()) |% `
    {
        write-host $_.DisplayName -ForegroundColor Red -BackgroundColor Yellow
        $t=[Text.Encoding]::GetEncoding($_.name)
        [string]$1=[string]::Empty
        90..200 |% `
        {
            try
            {
                $1+=(' '+$($t.getChars($_)))
            }
            catch
            {
                $1+="[$_]"
            }
        }
        $1 -replace '.{220}', "`$&`n"
    }

    There must be a better way?!?

    Monday, May 11, 2020 8:11 AM

All replies

  • did you looking for this?

    90..200 |% {[char]$_}

    or mb this:

    ([Text.Encoding]::GetEncodings()) |% {
    write-host $_.DisplayName -ForegroundColor Red -BackgroundColor Yellow
        $t=[Text.Encoding]::GetEncoding($_.name)
        $t.GetChars(90..200) -join ' '
    }


    The opinion expressed by me is not an official position of Microsoft


    • Marked as answer by Anthony Guyon Monday, May 11, 2020 12:45 PM
    • Unmarked as answer by Anthony Guyon Monday, May 11, 2020 12:45 PM
    • Edited by Vector BCO Monday, May 11, 2020 12:51 PM
    Monday, May 11, 2020 12:43 PM
  • Both of the above solutions have the same flaw as my solution, in that they require the operative to know what integer iterations are required to send into the character set to gain output. i.e. 0..256 - which may well be a valid range, however does not answer the actual question - which is:

    " Is there a way to produce all the characters in a character set  " Not a specific range which has been guessed at.


    Monday, May 11, 2020 3:51 PM
  • I would recommend starting by reviewing the definition of a character set.  All sets must satisfy the 0-255 base requirement.  Extended character sets would have to be double-byte or larger and cover the range.

    I am pretty sure that , if you search, you will find tables of sets that allow you t compare and see mappings between sets.


    \_(ツ)_/

    • Proposed as answer by jrv Tuesday, May 12, 2020 10:48 AM
    Monday, May 11, 2020 6:23 PM