更有效的字符串解析方法?

时间:2014-05-15 10:18:59

标签: vb.net

代码的第一部分是从Web检索数据。完成请求只需要一部分时间。代码的第二部分是分割数据,以便可以用不同的标签显示部分数据,完成此操作需要大约5-6秒? 这是为什么?可以更快地完成吗?

代码的第一部分(textbox1按键事件)

If e.KeyCode = Keys.Enter Then
        TextBox1.Text = UCase(TextBox1.Text)
        If TextBox1.Text = "" Then
            GoTo exx
        Else

            Dim strURL As String
            Dim strSymbol As String = TextBox1.Text
            strURL = " http://quote.yahoo.com/d/quotes.csv?" & _
                 "s=" & strSymbol & _
                 "&d=t" & _
            "&f=snl1pmwvj1l1"

            MessageBox.Show(RequestWebData(strURL))

代码和功能的第二部分:

  Label24.Text = (GetName2(RequestWebData(strURL), 3))
            Dim myText = Label24.Text
            Dim dIndex = myText.IndexOf("Inc.")
            If (dIndex > -1) Then
                Label24.Text = (Strings.Left(Label24.Text, dIndex + 4))
            Else
                Label24.Text = (Label24.Text)
            End If
            Dim myText2 = Label24.Text
            Dim dIndex2 = myText2.IndexOf("Common")
            If (dIndex2 > -1) Then
                Label24.Text = (Label24.Text.Replace("Common", ""))
            Else
                Label24.Text = (Label24.Text)
            End If
            Label6.Text = (GetName(RequestWebData(strURL), 4))
            Label6.Text = (GetName3(Label6.Text, 1))
            Label6.Text = FormatNumber(Label6.Text, 2)

            Label17.Text = (GetName(RequestWebData(strURL), 5))
            Label21.Text = (GetName(RequestWebData(strURL), 7))
            Dim x As String = GetName(RequestWebData(strURL), 8)
            Label30.Text = GetName3(x, 1)
            Label30.Text = FormatNumber(Label30.Text, 0)
            Label32.Text = GetName3(x, 2)

            TextBox2.Focus()

 Function GetName(ByVal LineIn As String, ByVal i As Integer) As String
    'Dim x As Integer
    Return LineIn.Split(""",")(i)
End Function
Function GetName2(ByVal LineIn As String, ByVal i As Integer) As String
    'Dim x As Integer
    Return LineIn.Split("""")(i)
End Function
Function GetName3(ByVal LineIn As String, ByVal i As Integer) As String
    'Dim x As Integer
    Return LineIn.Split(",")(i)
End Function

由于我使用这三个函数来分割数据,可能它是如此之慢?

0 个答案:

没有答案