Created
January 8, 2020 21:16
-
-
Save Goadstir/2037de9778a4f591a4e2f8df6c6aafb6 to your computer and use it in GitHub Desktop.
PowerShell: Remove the curly braces surrounding a string, or any character from within a string using an option within these examples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Remove the Curly Braces from a string such as after getting PSChildName. E.g. {636D9115-E54E-4673-B992-B51A8F8DDC8B} | |
| # Using trim : | |
| "{636D9115-E54E-4673-B992-B51A8F8DDC8B}".trim('{}') | |
| # Using multiple replace : | |
| "{636D9115-E54E-4673-B992-B51A8F8DDC8B}".Replace('{','').Replace('}','') | |
| # Using Replace with RegEx | |
| "{636D9115-E54E-4673-B992-B51A8F8DDC8B}" -replace '\{(.*)\}','$1' | |
| # Using pure RegEx : | |
| "{636D9115-E54E-4673-B992-B51A8F8DDC8B}" -match '\{(.*)\}' | |
| $Matches[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment