在具有引号 powershell 的字符串上使用替换运算符 [英] Using the replace operator on a string that has quotes powershell

查看:37
本文介绍了在具有引号 powershell 的字符串上使用替换运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找运行命令

foreach-object {$_ -replace

但是,我尝试使用的字符串可以描述为以下内容

However the string I am attempting to work with could be described as the follow

this string "has" quotes

整行是

foreach-object {$_ -replace "this string "has" quotes", "this string "won't have" quotes"}

如何使此引号填充行与 powershell 配合使用?

How do I make this quote filled line work with powershell?

推荐答案

你可以像 `" 那样转义嵌套的双引号,或者更好的是,使用单引号来引用字符串然后你不需要转义双引号,例如:

You can either escape the nested double quotes like so `" or better yet, use single quotes for quoting of the string then you won't need to escape the double quotes e.g.:

'this string "has" quotes'

注意:使用单引号,您不会在字符串中进行变量扩展.

Note: with single quotes you won't get variable expansion in a string.

这篇关于在具有引号 powershell 的字符串上使用替换运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆