Help with Trim and/or Split

Welcome Forums General PowerShell Q&A Help with Trim and/or Split

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 4 months ago.

  • Author
  • #5285

    Topics: 1562
    Replies: 0
    Points: 0
    Rank: Member

    by link12 at 2012-11-16 08:23:44

    How can I trim/split the following


    I basically want to trim the aa- and the -cc, but leave the computer name regardless if it has a "-" or not.

    by ArtB0514 at 2012-11-16 09:12:48

    Easy: takes two steps:
    1. Split the name on "-"
    2. Rejoin the name, skipping the first (id=0) and the last (id=count -1)

    $Original = $ComputerName -Split "-"
    $Final = (1..($Original.count – 2) | foreach {$Original[$_]}) -join "-"

    by link12 at 2012-11-16 09:18:56

    Worked like a charm. Can you briefly explain this line
    $Final = (1..($Original.count – 2) | foreach {$Original[$_]}) -join "-"


    by link12 at 2012-11-16 09:23:28

    I see your explaination above, nevermind. Thanks again

The topic ‘Help with Trim and/or Split’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort