String Split/Trim question

Welcome Forums General PowerShell Q&A String Split/Trim question

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

  • Author
  • #5261

    Points: 0
    Rank: Member

    by link12 at 2012-11-05 08:09:16

    I'm trying to use the code below to end up with only the "ddd" in the name and not "aaa-bbb-ccc-". I'm looking at a bunch of files in a directory with the same format that I would like
    to trim/split to only the end.

    File Format


    $a = get-childitem c:\testing | foreach-object {$_.BaseName} | Out-String
    foreach ($i in $a){

    In my output I get the first "ddd" but I also get "aaa"

    by link12 at 2012-11-05 10:07:41

    I figured it out. I removed the " | out-string"

    works great now.

    by RichardSiddaway at 2012-11-05 10:14:06

    This should do what you want
    Get-ChildItem -Path c:\testf | foreach { ($_.BaseName -split "-")[3] }

The topic ‘String Split/Trim question’ is closed to new replies.