2014-10-27 116 views
0

我對bash用正則表達式使用大括號替換部分字符串的能力非常熟悉。例如:Powershell字符串變量替換

a = "Hello, World!" 
echo "${a/World/Nancy}" 

以上將打印出「你好,南希!」 PowerShell能夠以這種方式進行子串合併嗎?還是有相當的選擇?

+0

可能重複(http://stackoverflow.com/questions/20157036/powershell-replace-characters-in-一個字符串)。這也有很多[示例](http://stackoverflow.com/search?q=powershell+string+replace)在SO – Matt 2014-10-27 17:47:24

回答

2

-replace操作者(支持正則表達式):的[Powershell的替換字符串中的字符]

$a = "Hello, World!" 
$a -replace "World","Nancy" 
+0

真棒,這正是我正在尋找的。謝謝! – HalosGhost 2014-10-27 17:44:32