Creating Range of Letters

PowerShell can easily provide a range of numbers, but creating them is not that easy - unless you convert ascii codes into characters:

65..90 | Foreach-Object { "$([char]$_):" }

Twitter This Tip! ReTweet this Tip!


Posted May 10 2010, 08:00 AM by ps1

Comments

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 wrote 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
on 05-10-2010 9:07 AM

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

Creating a Range of Letters, an Alternate Method | TechProsaic wrote Creating a Range of Letters, an Alternate Method | TechProsaic
on 05-10-2010 8:24 PM

Pingback from  Creating a Range of Letters, an Alternate Method | TechProsaic

madlogik wrote re: Creating Range of Letters
on 05-12-2010 5:48 PM

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 $  :)

Richard Giles wrote re: Creating Range of Letters
on 05-13-2010 1:17 PM

$_ 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:

...

excel formulas wrote re: Creating Range of Letters
on 06-09-2011 7:09 PM

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.

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.