New filters on the Home Feed, take a look!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Conosle output different from ISE
Post Body

Hello r/powershell,

I have two functions: New-BlockCharacter takes a character, and outputs a here string that represents this character:

Function New-BlockCharacter {

    [CmdletBinding()]

    PARAM(

        [char]$Character

    )

    Switch ($Character) {

        "A" {
@"
 ██████ 
 ██  ██ 
 ██████ 
 ██  ██ 
 ██  ██ 
"@
        }
        "B" {
@"
 █████  
 ██  ██ 
 █████  
 ██  ██ 
 █████  
"@
        }
        "C" {
@"
 ██████ 
 ██     
 ██     
 ██     
 ██████ 
"@
        }

    }

}       

An exmaple:

New-BlockCharacter -Character "a"
 ██████ 
 ██  ██ 
 ██████ 
 ██  ██ 
 ██  ██ 

The other function ConvertTo-BlockCharacter accepts a multi character string, calls New-BlockCharacter once for each character, and then "glues" the resulting here strings together. The result is a single multi line string that contains all block characters.

Function ConvertTo-BlockCharacter {

    [CmdletBinding()]

    PARAM (

        [String]$String="Test"

    )

    $Blockcharacters = foreach ($character in ($String.ToCharArray())) {

        New-BlockCharacter -Character $character

    }

    $sb = [System.Text.StringBuilder]::new()

    # iterate from first to last row of each character (is always 5)
    for ($i=0; $i -le 4; $i  ) {

        # iterate through each character
        foreach ($Blockcharacter in $Blockcharacters) {  

            # cut character in rows
            $BlockcharacterRows = $Blockcharacter -split "`n"

            # append current row of character to a new string
            [void]$sb.Append($($BlockcharacterRows[$i]))

        }

        # append new line to string
        [void]$sb.AppendLine()

        Write-Verbose ("`n$sb")

        # continue with next row

    }

    $sb.ToString()

}

An example:

ConvertTo-BlockCharacters -String ABC
 ██████  █████   ██████ 
 ██  ██  ██  ██  ██     
 ██████  █████   ██     
 ██  ██  ██  ██  ██     
 ██  ██  █████   ██████ 

It works fine, but only in ISE. If I run the same in the PS console, the output is rubbish:

ConvertTo-BlockCharacter -String abc
 ██████
 ██
 ██
 ██
 ██  ██  █████   ██████

I already tried to run it in the console of a different PC. I have no idea whats going on here. Can anybody help? Thank you

Author
Account Strength
90%
Account Age
15 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,540
Link Karma
3,347
Comment Karma
1,193
Profile updated: 4 days ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 years ago