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?










share|improve this question























  • 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














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?










share|improve this question























  • 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












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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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












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)






share|improve this answer






















  • 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


















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( $_ )





share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    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

























    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)






    share|improve this answer






















    • 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















    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)






    share|improve this answer






















    • 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













    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)






    share|improve this answer














    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)







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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

















    • 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













    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( $_ )





    share|improve this answer
























      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( $_ )





      share|improve this answer






















        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( $_ )





        share|improve this answer












        PS2 to PS5:



        97..(97+25) | % [char]$_ 


        Faster:



        (97..(97+25)).ForEach( [char]$_ )


        PS6+:



        'a'..'z' | % $_ 


        Faster:



        ('a'..'z').ForEach( $_ )






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 14:56









        Daniel Ferreira

        112




        112



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党