Help with Trim and/or Split

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

  • Author
    Posts
  • #5285

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

    How can I trim/split the following

    aa-computername-cc
    aa-computer-name-cc

    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 "-"

    Thanks

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

    I see your explaination above, nevermind. Thanks again

You must be logged in to reply to this topic.