试图找到引号字符的 IndexOf

Trying to find IndexOf a quote character

完整字符串:

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 一个 " 角色有什么想法吗?我试过使用 """,但这些编码中的 none 也可以。它不会识别报价。

你已经做对了 IndexOf,尽管我会使用 .indexOf('"')。该错误依赖于 Substring。但是,我不会走这条路...


您可以使用简单的正则表达式轻松捕获字符串:

\?did\s+=\s+([^"]*)

PowerShell:

$PDFDid = [regex]::Match($PDFReference , '\?did\s+=\s+([^"]*)').Groups[1].Value