完整字符串:
PDF引用=
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("InvestorL
ibrary_ILTocUC$LandingPanel$ildetail$lbNext", "", false, "", "/AO/Main.aspx?did
= 003711812@bull!nb2016!n160550603", false, true))
从上面我只想捕获003711812@bull!nb2016!n160550603
这就是我正在尝试的:
$PDFDid = $PDFReference.Substring($PDFReference.IndexOf('?did = ') + 7, ($PDFReference.IndexOf('?did = ') + 7 ) - ($PDFReference.IndexOf("`"")))
我的问题在于 $PDFReference.IndexOf("
"")`,因为这似乎是捕获完整字符串的最简洁方法,但我收到错误
Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the
string.
Parameter name: length"
有什么想法如何执行 IndexOf
"
字符吗?我尝试过使用 "
, "
、 和 "
但这些编码都不起作用。它不会识别报价。
最佳答案
尽管我会使用 .indexOf('"')
,但您已经正确执行了 IndexOf
。该错误依赖于 Substring
。不过,我不会走这条路...
您可以使用简单的正则表达式轻松捕获字符串:
\?did\s+=\s+([^"]*)
PowerShell:
$PDFDid = [regex]::Match($PDFReference , '\?did\s+=\s+([^"]*)').Groups[1].Value
关于powershell - 试图找到 IndexOf 引号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37703517/