Trim the space after Select-String commande PowerShell ( for removing multiple local git branch)

Issue

This Content is from Stack Overflow. Question asked by WolfCode

My Objective is removing multiple local git branch.

PS> git branch

  bug/5646
  chin-dev
* dev
  fea/account-manager
  fea/animation
  fea/charts
  fea/chat
  fea/dataTable
  fea/enquete
  fea/page-title
  fea/questionnaire
  fea/style
  hotfix
  master
  merge
  mod/dataTable
  question
  saif-dev
  support

My objective is removing all branch starting with ‘fea’, with this commande
PS> git branch -d $(git branch | Select-String -Pattern 'fea/') <– (Yes, I kown Select-String is matching string, but anyway ignore in that case)

Result with the commande

error: branch '  fea/account-manager' not found.
...
error: branch '  fea/questionnaire' not found.
error: branch '  fea/style' not found.

As you can see it return the matched line also with space.
So these anyway removing space with select-string?

Also i tried convert the result toString for using Trim()

PS > $(git branch | Select-String -Pattern 'fea/' ).ToString().Trim()
System.Object[]



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?