简体   繁体   English

删除或忽略字符串中的双引号-Powershell

[英]remove or ignore double quotes in a string - powershell

I think I have a simple problem but I can't seem to find the answer. 我认为我有一个简单的问题,但似乎找不到答案。

This is a part of the string I am working with 这是我正在使用的字符串的一部分

$text = "INDEPENDENT ELECTORAL AND BOUNDARIES COMMISSION
POLLING STATION: "ABC DEF GHIJKL (001)" 
STREAM:123"

When I try to work with this, I get an error because of the double quotes in $text. 当我尝试使用此方法时,由于$ text中的双引号引起错误。 I know I can escape the double quotes using a back tick, but the entire string is too big for me to go through it all. 我知道我可以使用反斜线转义双引号,但是整个字符串对于我来说太大了,无法全部使用。

I wonder if there is a simple way to ignore or remove all double (and single, too) quotes except for the first and last. 我想知道是否有一种简单的方法可以忽略或除去除第一个和最后一个以外的所有双引号(以及单引号)。

You can solve this by using here-strings: 您可以使用here-strings解决此问题:

$Text = @'
All the symbols I/ can ` hope for
between " the *>$ opening $() and closing ${}
of the symbols
'@

Use this: @' ... '@ 使用这个: @' ... '@

Your string would look like this: 您的字符串如下所示:

$text = @'
"INDEPENDENT ELECTORAL AND BOUNDARIES COMMISSION
POLLING STATION: "ABC DEF GHIJKL (001)" 
STREAM:123"
'@

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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