1

我正在尝试在 url 上使用 string.format 将多个值传递到字符串中。这可能是一个简单的错误,但我无法让以下代码工作。它甚至不构建字符串。有任何想法吗?

谢谢!

Public Sub getStockData()
    Dim client As New WebClient()
    Dim url As String
    Dim ticker As String = "MSFT"
    Dim lastPrice As String = "l1"
    Dim volume As String = "v0"
    Dim marketCap As String = "j1"
    Dim divYield As String = "x"
    Dim peRatio As String = "r"
    Dim eps As String = "e"

    url = String.Format("http://finance.yahoo.com/d/quotes.csv?s={0}&f={1}{2}{3}{4}{5}{6}", ticker, lastPrice, marketCap, divYield, peRatio, eps)
    Dim results As String = client.DownloadString(url)
    messagebox.show(results)
End Sub
4

1 回答 1

4

您有 7 个要插入的值(格式项 {0} 到 {6})但只提供其中六个:

url = String.Format(
    "http://finance.yahoo.com/d/quotes.csv?s={0}&f={1}{2}{3}{4}{5}{6}", 
    ticker, lastPrice, marketCap, divYield, peRatio, eps)

未使用名为“volume”的变量...

编辑:使用@SpectralGhost 指出的官方 MS 术语“格式项目”!

于 2012-02-03T22:53:30.797 回答