recently I've been trying to make a Universal app which checks stock price of a certain company. Currently I'm working with Windows Phone 8.1 ( I will start windows 8.1 once I get this working for Windows Phone 8.1). I'm using Yahoo finance, to get the stock. The problem is that its on csv format, which I can't figure out how to use. I have made this with appinventor before and now Im trying to do the same thing. I'm not a very good programmer so.. yeah.. can I get some help?
private async void CheckStock_Click(object sender, RoutedEventArgs e)
{
var client = new System.Net.Http.HttpClient(); // Add: using System.Net.Http;
var response = await client.GetAsync(new Uri("http://download.finance.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgv&e=.csv&s="+StockEnter.Text));
var result = await response.Content.ReadAsStringAsync();
ActualStock.Text = (result.ToString());
}
Everything works, but Instead of just showing the stock, it shows everything!: Here is an example: I tried checking stock for Microsoft. http://snag.gy/cLDGr.jpg How do I just make it show "47,98", which is the stock of microsoft.
Well, the short answer to this is that you should extract the second part of the result and show that. This can be done by splitting the string by the delimiter ,
, and then using the second part.
string[] values = result.ToString().Split(",");
string stockValue = values[1]; // values are 0-indexed, so 1 is the second string
ActualStock.Text = stockValue;