Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Replacing a String Inside Another String with PowerShell

$
0
0

Summary: Learn two different techniques to replace strings inside another string by using Windows PowerShell.

Hey, Scripting Guy! Question I have the following string: this`"is a string. I want to remove the quotation mark (") and replace it with nothing—no space, just nothing. I want the results to look like this: thisis a string. The backtick (`) is used to “escape” the quotation mark. How can I use the Replace method to replace the quotation mark with nothing, if the string is held in a variable $arr?

       Hey, Scripting Guy! Answer There are several approaches to this. Here are a couple of solutions:

  • Use the Replace method from the system.string .NET framework class.

$arr.Replace("`"","")

  • Use the ascii value of the quotation mark, and use the Replace method from the system.string .NET framework class.

$arr.Replace([char]34,"")


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>