none
reverse string getting issue RRS feed

  • Question

  • $s="Last.Mid.First"
    $t= $s,index(".")
    $right=$t.substring(0,$pos)
    $left=$t.substring($pos+1)
    

    I want to concatenate $left+$right (output as First.Mid.Last) but I can not use [array]::reverse($right) because I am getting output in string and I do not want to convert $right to array $right =@() in this case how to concatenate the string array

    Monday, April 15, 2019 3:13 PM

Answers

  • Why not use -split operator?


    PS C:\> $s = "Last.Mid.First"
    PS C:\> $s -split '\.'
    Last
    Mid
    First
    PS C:\>
    


    -- Bill Stewart [Bill_Stewart]

    Monday, April 15, 2019 3:46 PM
    Moderator

All replies

  • Why not use -split operator?


    PS C:\> $s = "Last.Mid.First"
    PS C:\> $s -split '\.'
    Last
    Mid
    First
    PS C:\>
    


    -- Bill Stewart [Bill_Stewart]

    Monday, April 15, 2019 3:46 PM
    Moderator
  • THe issue with reverse, First.Mid.Last is not getting in output
    Wednesday, April 17, 2019 2:44 PM
  • Sorry, but I do not understand your question.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 17, 2019 2:51 PM
    Moderator
  • Another wild guess:

    $s='Last.Mid.First'
    ($s -split '\.')[2..0] -join '.'


    \_(ツ)_/

    Wednesday, April 17, 2019 4:53 PM
  • We can also use the long method which avoids length.

    $s="Last.Mid.First"
    $a = $s -split '\.'
    [array]::Reverse($a)
    $a -join '\.'


    \_(ツ)_/

    Wednesday, April 17, 2019 4:58 PM