PowerShell can easily provide a range of numbers, but creating them is not that easy - unless you convert ascii codes into characters:
ReTweet this Tip!
Pingback from Twitter Trackbacks for Power Tips: Creating Range of Letters: PowerShell can easily provide a range of numbers, but creating them is ... ^f3 [powershell.com] on Topsy.com
Pingback from Creating a Range of Letters, an Alternate Method | TechProsaic
Please help me understand this syntax exactly.
I would have wrote it that way:
[code] 65..90 | Foreach-Object { $_ = [char]$_ ;$_} [/code]
I would like to understand what is the thinking of : "$([char]$_):"
please compare the way I wrote it (a two step process)...
I do not understand the use of $ and $_ completely... and this is a perfect learning point for me.
well.. I hope someone will teach me what I'm missing about $ :)
$_ is a placeholder for the current object being passed through the pipeline
"$(...):" is used because we need to append the char representation of the number with a ":"
If you only had "([char]$_):" then you would get:
([char]65):
([char]66):
...
instead of "$([char]$_):" which yields:
A:
B:
It isn't too difficult to find a list of ASCII codes for each character by just doing a quick internet search, but I've done that one better. A few years ago I was doing a project for my college class and I created an Excel spreadsheet, and by using some intricate formulas, I created a character/ASCII converter of sorts. You type in any character and it will display the ASCII code in the next column. It took a few hours to perfect, but it's really neat. I can upload it if anybody would like a copy.