Splitting a string into separate variables

后端 未结 5 1789
死守一世寂寞
死守一世寂寞 2020-12-13 16:42

I have a string, which I have split using the code $CreateDT.Split(\" \"). I now want to manipulate two separate strings in different ways. How can I separate t

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 17:18

    An array is created with the -split operator. Like so,

    $myString="Four score and seven years ago"
    $arr = $myString -split ' '
    $arr # Print output
    Four
    score
    and
    seven
    years
    ago
    

    When you need a certain item, use array index to reach it. Mind that index starts from zero. Like so,

    $arr[2] # 3rd element
    and
    $arr[4] # 5th element
    years
    

提交回复
热议问题