Split string with PowerShell and do something with each token

后端 未结 4 1541
[愿得一人]
[愿得一人] 2020-12-04 23:27

I want to split each line of a pipe on spaces, and then print each token on its own line.

I realise that I can get this result using:

(cat someFileIn         


        
4条回答
  •  醉酒成梦
    2020-12-05 00:09

    -split outputs an array, and you can save it to a variable like this:

    $a = -split 'Once  upon    a     time'
    $a[0]
    
    Once
    

    Another cute thing, you can have arrays on both sides of an assignment statement:

    $a,$b,$c = -split 'Once  upon    a'
    $c
    
    a
    

提交回复
热议问题