{"id":524,"date":"2014-10-16T11:59:00","date_gmt":"2014-10-16T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/10\/16\/powertip-use-powershell-to-remove-characters-in-a-string\/"},"modified":"2014-10-16T11:59:00","modified_gmt":"2014-10-16T11:59:00","slug":"powertip-use-powershell-to-remove-characters-in-a-string","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-use-powershell-to-remove-characters-in-a-string\/","title":{"rendered":"PowerTip: Use PowerShell to Remove Characters in a String"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Learn how to use Windows PowerShell to remove specific characters in a string.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;I have a string that includes braces:<\/p>\n<p style=\"margin-left:120px\">$a = &#8216;{Abcde}&#8217;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;I want to remove the braces, but keep the text string inside the braces. <br \/>&nbsp; &nbsp;How can I do this by using Windows PowerShell?<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Use the&nbsp;<b>&ndash;Replace<\/b>&nbsp;operator, create a regular expression pattern that includes only the braces you want to remove, <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and then write the results back to the variable, for example:<\/p>\n<p style=\"margin-left:120px\">PS C:&gt; $a = &#8216;{Abcde}&#8217;<\/p>\n<p style=\"margin-left:120px\">PS C:&gt; $a -replace &#8216;[{}]&#8217;,&#8221;<\/p>\n<p style=\"margin-left:120px\">abcde<\/p>\n<p style=\"margin-left:120px\">PS C:&gt; $a = $a -replace &#8216;[{}]&#8217;,&#8221;<\/p>\n<p style=\"margin-left:120px\">PS C:&gt; $a<\/p>\n<p style=\"margin-left:120px\">abcde<\/p>\n<p style=\"margin-left:60px\"><b>Note&nbsp;<\/b>&nbsp;This command uses single, <span>back-to-back<\/span>&nbsp;quotation marks .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use Windows PowerShell to remove specific characters in a string. &nbsp;I have a string that includes braces: $a = &#8216;{Abcde}&#8217; &nbsp; &nbsp;I want to remove the braces, but keep the text string inside the braces. &nbsp; &nbsp;How can I do this by using Windows PowerShell? &nbsp;Use the&nbsp;&ndash;Replace&nbsp;operator, create a regular expression [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[356,174,3,4,45],"class_list":["post-524","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-powertip","tag-regular-expressions","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Windows PowerShell to remove specific characters in a string. &nbsp;I have a string that includes braces: $a = &#8216;{Abcde}&#8217; &nbsp; &nbsp;I want to remove the braces, but keep the text string inside the braces. &nbsp; &nbsp;How can I do this by using Windows PowerShell? &nbsp;Use the&nbsp;&ndash;Replace&nbsp;operator, create a regular expression [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=524"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/524\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}