Powershell loop with numbers to alphabet
up vote
0
down vote
favorite
I need help with the following:
Create a for loop based on the conditions that the index is initialized to 0, $test is less than 26, and the index is incremented by 1
For each iteration, print the current letter of the alphabet. Start at the letter A. Thus, for each iteration, a single letter is printed on a separate line.
I am not able to increment the char each time the loop runs
for ($test = 0; $test -lt 26; $test++)
[char]65
I have tried multiple attempts with trying to increment the char 65 through 90 with no success.
Is there an easier way to increment the alphabet to show a letter for each loop that is ran?
powershell increment alphabet
add a comment |
up vote
0
down vote
favorite
I need help with the following:
Create a for loop based on the conditions that the index is initialized to 0, $test is less than 26, and the index is incremented by 1
For each iteration, print the current letter of the alphabet. Start at the letter A. Thus, for each iteration, a single letter is printed on a separate line.
I am not able to increment the char each time the loop runs
for ($test = 0; $test -lt 26; $test++)
[char]65
I have tried multiple attempts with trying to increment the char 65 through 90 with no success.
Is there an easier way to increment the alphabet to show a letter for each loop that is ran?
powershell increment alphabet
0=A 1=B 2=C 3=D ....25=Z
– vnavna
Sep 8 '17 at 5:41
0..25 | % [char] ($_ + [byte][char] 'A')
– David Brabant
Sep 8 '17 at 6:40
if all you want it the range of uppercase letters, this will do it ...[char]('A'[0]..'Z'[0])
. [grin]
– Lee_Dailey
Nov 11 at 17:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need help with the following:
Create a for loop based on the conditions that the index is initialized to 0, $test is less than 26, and the index is incremented by 1
For each iteration, print the current letter of the alphabet. Start at the letter A. Thus, for each iteration, a single letter is printed on a separate line.
I am not able to increment the char each time the loop runs
for ($test = 0; $test -lt 26; $test++)
[char]65
I have tried multiple attempts with trying to increment the char 65 through 90 with no success.
Is there an easier way to increment the alphabet to show a letter for each loop that is ran?
powershell increment alphabet
I need help with the following:
Create a for loop based on the conditions that the index is initialized to 0, $test is less than 26, and the index is incremented by 1
For each iteration, print the current letter of the alphabet. Start at the letter A. Thus, for each iteration, a single letter is printed on a separate line.
I am not able to increment the char each time the loop runs
for ($test = 0; $test -lt 26; $test++)
[char]65
I have tried multiple attempts with trying to increment the char 65 through 90 with no success.
Is there an easier way to increment the alphabet to show a letter for each loop that is ran?
powershell increment alphabet
powershell increment alphabet
edited Sep 8 '17 at 5:45
asked Sep 8 '17 at 5:37
vnavna
814
814
0=A 1=B 2=C 3=D ....25=Z
– vnavna
Sep 8 '17 at 5:41
0..25 | % [char] ($_ + [byte][char] 'A')
– David Brabant
Sep 8 '17 at 6:40
if all you want it the range of uppercase letters, this will do it ...[char]('A'[0]..'Z'[0])
. [grin]
– Lee_Dailey
Nov 11 at 17:13
add a comment |
0=A 1=B 2=C 3=D ....25=Z
– vnavna
Sep 8 '17 at 5:41
0..25 | % [char] ($_ + [byte][char] 'A')
– David Brabant
Sep 8 '17 at 6:40
if all you want it the range of uppercase letters, this will do it ...[char]('A'[0]..'Z'[0])
. [grin]
– Lee_Dailey
Nov 11 at 17:13
0=A 1=B 2=C 3=D ....25=Z
– vnavna
Sep 8 '17 at 5:41
0=A 1=B 2=C 3=D ....25=Z
– vnavna
Sep 8 '17 at 5:41
0..25 | % [char] ($_ + [byte][char] 'A')
– David Brabant
Sep 8 '17 at 6:40
0..25 | % [char] ($_ + [byte][char] 'A')
– David Brabant
Sep 8 '17 at 6:40
if all you want it the range of uppercase letters, this will do it ...
[char]('A'[0]..'Z'[0])
. [grin]– Lee_Dailey
Nov 11 at 17:13
if all you want it the range of uppercase letters, this will do it ...
[char]('A'[0]..'Z'[0])
. [grin]– Lee_Dailey
Nov 11 at 17:13
add a comment |
2 Answers
2
active
oldest
votes
up vote
5
down vote
accepted
You can sum your loop index with 65. So, it'll be: 0 + 65 = A, 1 + 65 = B ...
for ($test = 0; $test -lt 26; $test++)
[char](65 + $test)
for ($test = 0; $test -lt 26; $test++) $char = [char](65 +$test) Write-Host $char Your suggestion worked out great. Thank you
– vnavna
Sep 8 '17 at 14:33
add a comment |
up vote
1
down vote
PS2 to PS5:
97..(97+25) | % [char]$_
Faster:
(97..(97+25)).ForEach( [char]$_ )
PS6+:
'a'..'z' | % $_
Faster:
('a'..'z').ForEach( $_ )
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
You can sum your loop index with 65. So, it'll be: 0 + 65 = A, 1 + 65 = B ...
for ($test = 0; $test -lt 26; $test++)
[char](65 + $test)
for ($test = 0; $test -lt 26; $test++) $char = [char](65 +$test) Write-Host $char Your suggestion worked out great. Thank you
– vnavna
Sep 8 '17 at 14:33
add a comment |
up vote
5
down vote
accepted
You can sum your loop index with 65. So, it'll be: 0 + 65 = A, 1 + 65 = B ...
for ($test = 0; $test -lt 26; $test++)
[char](65 + $test)
for ($test = 0; $test -lt 26; $test++) $char = [char](65 +$test) Write-Host $char Your suggestion worked out great. Thank you
– vnavna
Sep 8 '17 at 14:33
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
You can sum your loop index with 65. So, it'll be: 0 + 65 = A, 1 + 65 = B ...
for ($test = 0; $test -lt 26; $test++)
[char](65 + $test)
You can sum your loop index with 65. So, it'll be: 0 + 65 = A, 1 + 65 = B ...
for ($test = 0; $test -lt 26; $test++)
[char](65 + $test)
edited Sep 8 '17 at 5:59
answered Sep 8 '17 at 5:53
Cassio Farias Machado
664
664
for ($test = 0; $test -lt 26; $test++) $char = [char](65 +$test) Write-Host $char Your suggestion worked out great. Thank you
– vnavna
Sep 8 '17 at 14:33
add a comment |
for ($test = 0; $test -lt 26; $test++) $char = [char](65 +$test) Write-Host $char Your suggestion worked out great. Thank you
– vnavna
Sep 8 '17 at 14:33
for ($test = 0; $test -lt 26; $test++) $char = [char](65 +$test) Write-Host $char Your suggestion worked out great. Thank you
– vnavna
Sep 8 '17 at 14:33
for ($test = 0; $test -lt 26; $test++) $char = [char](65 +$test) Write-Host $char Your suggestion worked out great. Thank you
– vnavna
Sep 8 '17 at 14:33
add a comment |
up vote
1
down vote
PS2 to PS5:
97..(97+25) | % [char]$_
Faster:
(97..(97+25)).ForEach( [char]$_ )
PS6+:
'a'..'z' | % $_
Faster:
('a'..'z').ForEach( $_ )
add a comment |
up vote
1
down vote
PS2 to PS5:
97..(97+25) | % [char]$_
Faster:
(97..(97+25)).ForEach( [char]$_ )
PS6+:
'a'..'z' | % $_
Faster:
('a'..'z').ForEach( $_ )
add a comment |
up vote
1
down vote
up vote
1
down vote
PS2 to PS5:
97..(97+25) | % [char]$_
Faster:
(97..(97+25)).ForEach( [char]$_ )
PS6+:
'a'..'z' | % $_
Faster:
('a'..'z').ForEach( $_ )
PS2 to PS5:
97..(97+25) | % [char]$_
Faster:
(97..(97+25)).ForEach( [char]$_ )
PS6+:
'a'..'z' | % $_
Faster:
('a'..'z').ForEach( $_ )
answered Nov 11 at 14:56
Daniel Ferreira
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46109334%2fpowershell-loop-with-numbers-to-alphabet%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
0=A 1=B 2=C 3=D ....25=Z
– vnavna
Sep 8 '17 at 5:41
0..25 | % [char] ($_ + [byte][char] 'A')
– David Brabant
Sep 8 '17 at 6:40
if all you want it the range of uppercase letters, this will do it ...
[char]('A'[0]..'Z'[0])
. [grin]– Lee_Dailey
Nov 11 at 17:13