简体   繁体   English

vb.net中url上的string.format

[英]string.format on url in vb.net

I am trying to use string.format on a url to pass several values into the string. 我试图在URL上使用string.format将多个值传递给字符串。 It's probably a simple error but I cannot get the following code to work. 这可能是一个简单的错误,但是我无法使以下代码正常工作。 It doesn't even build the string. 它甚至不构建字符串。 Any ideas? 有任何想法吗?

Thanks! 谢谢!

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

You have 7 values you want to insert (format items {0} thru {6}) but only supply six of them: 您有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)

the variable named "volume" is not being used ... 名为“ volume”的变量未使用...

EDIT: Using the official MS term "format items" as pointed out by @SpectralGhost! 编辑:使用@SpectralGhost指出的官方MS术语“格式项”!

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

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