简体   繁体   English

如何编写脚本以读取Powershell中的双引号

[英]how to write a script to read double quotes in powershell

Hi every one i am trying to read a string which is enclosed in double quotes within a file eg "cars" : I am using this command but unable to read it may be I am not using the right format to read the quotes 大家好,我正在尝试读取一个字符串,该字符串用双引号括在文件中,例如“ cars”:我正在使用此命令,但无法读取,可能是因为我没有使用正确的格式来读取引号

$houseid = $json |Get-Content |Select-String -pattern ""houseid":"| measure | select -exp count

write-host "houseid = " $houseid 

I am reading the file from json file 我正在从json文件读取文件

Wrap you pattern in single quotes when it contains quotes. 当包含引号时,将您的模式括在单引号中。 Although it's not necessary, you should add -SimpleMatch to specify that it is a normal string-pattern and not regex. 尽管不是必需的,但是您应该添加-SimpleMatch来指定它是普通的字符串模式而不是regex。

#Valid sample
'"houseid":myjsonvalue' | Select-String -Pattern '"houseid":' -SimpleMatch | measure | select -ExpandProperty count    
1

#Invalid sample
'houseid:myjsonvalue' | Select-String -Pattern '"houseid":' -SimpleMatch | measure | select -ExpandProperty count
0

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

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