Powershell 变量扩展以及单引号
Powershell variable expansion along with a single quote
在下面的表达式中,我希望将 $key 变量扩展为
“//配置[@navtitle='Some Report']”
我该如何实现?知道 $key 值来自外部文件
$key = "Some Report"
Xml.SelectNodes("//configuration[@title=$key]")
不会在双引号内解析单引号。您可以将单引号放在 $key 或字符串中:
$key = "'Some Report'"
"//configuration[@title=$key]"
输出:
//configuration[@title='Some Report']
或
$key = "Some Report"
"//configuration[@title='$key']"
在下面的表达式中,我希望将 $key 变量扩展为
“//配置[@navtitle='Some Report']”
我该如何实现?知道 $key 值来自外部文件
$key = "Some Report"
Xml.SelectNodes("//configuration[@title=$key]")
不会在双引号内解析单引号。您可以将单引号放在 $key 或字符串中:
$key = "'Some Report'"
"//configuration[@title=$key]"
输出:
//configuration[@title='Some Report']
或
$key = "Some Report"
"//configuration[@title='$key']"