简体   繁体   中英

Powershell string variable substitution

I am quite familiar with bash's ability to substitute parts of strings in a regex-ish fashion using braces. Eg:

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

The above will print "Hello, Nancy!" Does powershell have the ability to do substring-subtitution in this way, or is there an equivalent alternative?

The -replace operator (supports regex):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM