0

我正在使用我的 vb.net 应用程序从网站获取 3 行文本,并且我只想在按下按钮时在我的标签中显示第二行。我目前拥有的代码向我展示了所有 3 行。我怎样才能只显示第二行。

Dim webAddress As String = "Website"

    Dim reader As StreamReader
    Dim request As WebRequest
    Dim response As WebResponse
    Dim data As String = ""

    Try
        request = WebRequest.Create(webAddress)
        request.Timeout = 30000
        response = request.GetResponse()
        reader = New StreamReader(response.GetResponseStream())
        data = reader.ReadToEnd
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
4

2 回答 2

1

您可以在 ReadToEnd 之后执行此操作:

Label1.Text = Split(data, VBCrLf)(1)
于 2013-04-02T17:31:28.820 回答
0

阅读单行:

reader.ReadLine() 'read and discard the first line
data = reader.ReadLine() 'read the line you want
reader.ReadToEnd 'read and discard the rest
于 2013-04-02T17:32:46.490 回答