J
jason
While I wait for my books to arrive.. anticipating the RTFM
responses... I am trying to understand the C# code below. The code is
suppose to be scraping stoke quote info off the MSN site. To help get
me started.
Can somebody please explain these three lines of code.
this.symbol = symbol; //( Is this saying set symbol to the value
passed to the function.. did I even say that right.. drawing no
distinction between the argument defined as symbol and the local
variable?? is this really neccessary?)
QuoteFetch q = new QuoteFetch(args[0]); //(Is is this saying define q
as type Quotefetch with the first argument passed)
Console.WriteLine("{0} = {1}", args[0], q.Last); .. //(especially
q.Last is this saying call Last with a value of q)
<code below .. btw thank you in advance to the original author>
/*
A Programmer's Introduction to C# (Second Edition)
by Eric Gunnerson
Publisher: Apress L.P.
ISBN: 1-893115-62-3
*/
// 32 - .NET Frameworks Overview\Reading Web Pages
// copyright 2000 Eric Gunnerson
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
class QuoteFetch
{
public QuoteFetch(string symbol)
{
this.symbol = symbol;
}
public string Last
{
get
{
string url =
"http://moneycentral.msn.com/scripts/webquote.dll?ipage=qd&Symbol=";
url += symbol;
ExtractQuote(ReadUrl(url));
return(last);
}
}
string ReadUrl(string url)
{
Uri uri = new Uri(url);
//Create the request object
WebRequest req = WebRequest.Create(uri);
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
return(s);
}
void ExtractQuote(string s)
{
// Line like: "Last</TD><TD ALIGN=RIGHT NOWRAP><B> 78
3/16"
Regex lastmatch = new Regex(@"Last\D+(?<last>.+)<\/B>");
last = lastmatch.Match(s).Groups[1].ToString();
}
string symbol;
string last;
}
public class ReadingWebPages
{
public static void Main(string[] args)
{
if (args.Length != 1)
Console.WriteLine("Quote <symbol>");
else
{
// GlobalProxySelection.Select = new
DefaultControlObject("proxy", 80);
QuoteFetch q = new QuoteFetch(args[0]);
Console.WriteLine("{0} = {1}", args[0], q.Last);
}
}
}
responses... I am trying to understand the C# code below. The code is
suppose to be scraping stoke quote info off the MSN site. To help get
me started.
Can somebody please explain these three lines of code.
this.symbol = symbol; //( Is this saying set symbol to the value
passed to the function.. did I even say that right.. drawing no
distinction between the argument defined as symbol and the local
variable?? is this really neccessary?)
QuoteFetch q = new QuoteFetch(args[0]); //(Is is this saying define q
as type Quotefetch with the first argument passed)
Console.WriteLine("{0} = {1}", args[0], q.Last); .. //(especially
q.Last is this saying call Last with a value of q)
<code below .. btw thank you in advance to the original author>
/*
A Programmer's Introduction to C# (Second Edition)
by Eric Gunnerson
Publisher: Apress L.P.
ISBN: 1-893115-62-3
*/
// 32 - .NET Frameworks Overview\Reading Web Pages
// copyright 2000 Eric Gunnerson
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
class QuoteFetch
{
public QuoteFetch(string symbol)
{
this.symbol = symbol;
}
public string Last
{
get
{
string url =
"http://moneycentral.msn.com/scripts/webquote.dll?ipage=qd&Symbol=";
url += symbol;
ExtractQuote(ReadUrl(url));
return(last);
}
}
string ReadUrl(string url)
{
Uri uri = new Uri(url);
//Create the request object
WebRequest req = WebRequest.Create(uri);
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
return(s);
}
void ExtractQuote(string s)
{
// Line like: "Last</TD><TD ALIGN=RIGHT NOWRAP><B> 78
3/16"
Regex lastmatch = new Regex(@"Last\D+(?<last>.+)<\/B>");
last = lastmatch.Match(s).Groups[1].ToString();
}
string symbol;
string last;
}
public class ReadingWebPages
{
public static void Main(string[] args)
{
if (args.Length != 1)
Console.WriteLine("Quote <symbol>");
else
{
// GlobalProxySelection.Select = new
DefaultControlObject("proxy", 80);
QuoteFetch q = new QuoteFetch(args[0]);
Console.WriteLine("{0} = {1}", args[0], q.Last);
}
}
}