title: How to select a value from a comma delimited string?
body: <p>I have a string that contains comma delimited text.  The comma delimited text comes from an excel .csv file so there are hundreds of rows of data that are seven columns wide.  An example of a row from this file is:</p>
  
  <p>2012-10-01,759.05,765,756.21,761.78,3168000,761.78</p>
  
  <p>I want to search through the hundreds of rows by the date in the first column.  Once I find the correct row I want to extract the number in the first position of the comma delimited string so in this case I want to extract the number 759.05 and assign it to variable "Open".</p>
  
  <p>My code so far is:</p>
  
  <pre><code>strURL = "http://ichart.yahoo.com/table.csv?s=" &amp; tickerValue
  strBuffer = RequestWebData(strURL)
  
  Dim Year As String = 2012
  Dim Quarter As String = Q4
  If Quarter = "Q4" Then
      Dim Open As Integer =
  End If
  </code></pre>
  
  <p>Once I can narrow it down to the right row I think something like row.Split(",")(1).Trim) might work.  </p>
  
  <p>I've done quite a bit of research but I can't solve this on my own.  Any suggestions!?! </p>
  
  <p><em><strong>ADDITIONAL INFORMATION:</em></strong></p>
  
  <pre><code>Private Function RequestWebData(ByVal pstrURL As String) As String
      Dim objWReq As WebRequest
      Dim objWResp As WebResponse
      Dim strBuffer As String
      'Contact the website
      objWReq = HttpWebRequest.Create(pstrURL)
      objWResp = objWReq.GetResponse()
      'Read the answer from the Web site and store it into a stream
      Dim objSR As StreamReader
      objSR = New StreamReader(objWResp.GetResponseStream)
      strBuffer = objSR.ReadToEnd
      objSR.Close()
  
      objWResp.Close()
  
      Return strBuffer
  End Function 
  </code></pre>
  
  <p><em><strong>MORE ADDITIONAL INFORMATION:</em></strong></p>
  
  <p>A more complete picture of my code</p>
  
  <pre><code>Dim tickerArray() As String = {"GOOG", "V", "AAPL", "BBBY", "AMZN"}
  
  For Each tickerValue In Form1.tickerArray
  
          Dim strURL As String
          Dim strBuffer As String
          'Creates the request URL for Yahoo
          strURL = "http://ichart.yahoo.com/table.csv?s=" &amp; tickerValue
  
          strBuffer = RequestWebData(strURL)
  
          'Create Array
          Dim lines As Array = strBuffer.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
  
          'Add Rows to DataTable
          dr = dt.NewRow()
          dr("Ticker") = tickerValue
          For Each columnQuarter As DataColumn In dt.Columns
              Dim s As String = columnQuarter.ColumnName
              If s.Contains("-") Then
                  Dim words As String() = s.Split("-")
                  Dim Year As String = words(0)
                  Dim Quarter As String = words(1)
                  Dim MyValue As String
                  Dim Open As Integer
                  If Quarter = "Q1" Then MyValue = Year &amp; "-01-01"
                  If Quarter = "Q2" Then MyValue = Year &amp; "-04-01"
                  If Quarter = "Q3" Then MyValue = Year &amp; "-07-01"
                  If Quarter = "Q4" Then MyValue = Year &amp; "-10-01"
                  For Each line In lines
                      Debug.WriteLine(line)
                      If line.Split(",")(0).Trim = MyValue Then Open = line.Split(",")(1).Trim
                      dr(columnQuarter) = Open
                  Next
              End If
  
          Next
          dt.Rows.Add(dr)
      Next
  </code></pre>
  
  <p>Right now in the <code>For Each line in lines</code> loop, <code>Debug.WriteLine(line)</code> outputs 2,131 lines:</p>
  
  <p>From</p>
  
  <pre><code>Date,Open,High,Low,Close,Volume,Adj Close
  2013-02-05,761.13,771.11,759.47,765.74,1870700,765.74
  2013-02-04,767.69,770.47,758.27,759.02,3040500,759.02
  2013-02-01,758.20,776.60,758.10,775.60,3746100,775.60
  </code></pre>
  
  <p>All the way to...</p>
  
  <pre><code>2004-08-19,100.00,104.06,95.96,100.34,22351900,100.34
  </code></pre>
  
  <p>But, what I expect is for <code>Debug.WriteLine(line)</code> to output one line at a time in the <code>For Each line in lines</code> loop.  So I would expect the first output to be <code>Date,Open,High,Low,Close,Volume,Adj Close</code> and the next output to be <code>2013-02-05,761.13,771.11,759.47,765.74,1870700,765.74</code>.  I expect this to happen 2,131 times until the last output is <code>2004-08-19,100.00,104.06,95.96,100.34,22351900,100.34</code></p>