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.
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
Subreddit
Post Details
- Posted
- 6 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/PowerShell/...