Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
QuestionPlease help. Printing datagridview issue... Pin
JollyMansArt30-Nov-09 5:11
JollyMansArt30-Nov-09 5:11 
AnswerRe: Please help. Printing datagridview issue... Pin
JollyMansArt30-Nov-09 11:23
JollyMansArt30-Nov-09 11:23 
QuestionRegex question Pin
kanchoette30-Nov-09 4:28
kanchoette30-Nov-09 4:28 
AnswerRe: Regex question Pin
OriginalGriff30-Nov-09 4:47
mveOriginalGriff30-Nov-09 4:47 
AnswerRe: Regex question PinPopular
PIEBALDconsult30-Nov-09 4:58
mvePIEBALDconsult30-Nov-09 4:58 
QuestionHow to Get the MSI installer Path Pin
coolpjmartin30-Nov-09 4:27
coolpjmartin30-Nov-09 4:27 
AnswerRe: How to Get the MSI installer Path Pin
The Man from U.N.C.L.E.30-Nov-09 7:43
The Man from U.N.C.L.E.30-Nov-09 7:43 
Questionregular expression in c# [modified] Pin
benjamin yap30-Nov-09 1:29
benjamin yap30-Nov-09 1:29 
Hi,

i want to retrieve some content from a webpage.

The method below retrieve the webpage content (in html).
public string GetWebpageContent(string StockQuote)
{
    //Store url + desired Stock Quote
    //E.g. NYSE, MSFT
    string serverURL = "http://www.google.com/finance?q=" + StockQuote;

    //Create a HTTP request based on url
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverURL);

    //Retrieve byte response from server base on the above request
    WebResponse response = request.GetResponse();

    //Retrieve content using StreamReader
    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII);

    //Read content
    string retVal = reader.ReadToEnd();

    //Close the stream reader
    reader.Close();

    //Return data
    return retVal;
}



Below method retrieve the stockprice in the web content. the html i wan to read consist this

<div>After Hours:&nbsp;<span class=bld id="ref_21913_el">10.60</span>


I wan to retrieve the value 10.60

The id="ref_21913_el" is not a fix value, so i have to read base on
<span class=bld....


public string GetStockPrice()
  {
      //Used to store the reverse Stock Price
      StringBuilder ReversePrice = new StringBuilder();

      //Store the actual price
      string Price = "";

      //Match the webpage content with the following pattern

      MatchCollection StockQuote = Regex.Matches(urlContent, "", RegexOptions.Singleline);

      //Retrieve the first matched result
      string StockPriceTag = StockQuote[0].Value; //"<span class=\"pr\">\n<span id=\"ref_705173_l\">26.83</span>"

      //Remove closing </span> tag
      string WithoutEndSpanTag = StockPriceTag.Remove(StockPriceTag.Length - 7, 7); //<span class=\"pr\">\n<span id=\"ref_705173_l\">26.83

      //Traverse through individual characters starting from the back
      for (int i = WithoutEndSpanTag.Length - 1; i >= 0; i--)
      {
          //Covert string to individual characters
          char[] AllChar = WithoutEndSpanTag.ToCharArray();

          //Check current item is not '>'
          if (AllChar[i] != '>')
          {
              ReversePrice.Append(AllChar[i]);
          }

          //MeetGreaterSymbol is true;
          else
          {
              //Covert string to individual characters
              char[] arr = ReversePrice.ToString().ToCharArray();

              //Reverse the order
              Array.Reverse(arr);

              //New string object
              Price = new string(arr);

              //Break out from loop
              break;
          }
      }

      //Return result
      return tbxStockQuote.Text + ", $" + Price;
  }



how do i change my MatchCollection StockQuote = Regex.Matches(urlContent, "<span class=bld(.*?)</span>", RegexOptions.Singleline);

so i can read the 10.60 value?

modified on Monday, November 30, 2009 7:37 AM

AnswerRe: regular expression in c# Pin
vivasaayi30-Nov-09 2:07
vivasaayi30-Nov-09 2:07 
AnswerRe: regular expression in c# Pin
PIEBALDconsult30-Nov-09 5:06
mvePIEBALDconsult30-Nov-09 5:06 
QuestionPlay one or more files in single execution Pin
yesu prakash30-Nov-09 1:28
yesu prakash30-Nov-09 1:28 
AnswerRe: Play one or more files in single execution Pin
Covean30-Nov-09 1:52
Covean30-Nov-09 1:52 
AnswerRe: Play one or more files in single execution Pin
souidi abderrahman30-Nov-09 3:24
souidi abderrahman30-Nov-09 3:24 
QuestionSpeech Recognition using .net framework 3.5 Pin
krinaljariwala30-Nov-09 1:04
krinaljariwala30-Nov-09 1:04 
AnswerRe: Speech Recognition using .net framework 3.5 Pin
Abhishek Sur30-Nov-09 1:31
professionalAbhishek Sur30-Nov-09 1:31 
GeneralRe: Speech Recognition using .net framework 3.5 Pin
krinaljariwala30-Nov-09 1:44
krinaljariwala30-Nov-09 1:44 
GeneralRe: Speech Recognition using .net framework 3.5 Pin
Abhishek Sur30-Nov-09 2:09
professionalAbhishek Sur30-Nov-09 2:09 
QuestionSetting DataGridView ColumnHeader text Pin
kanchoette30-Nov-09 0:50
kanchoette30-Nov-09 0:50 
AnswerRe: Setting DataGridView ColumnHeader text Pin
souidi abderrahman30-Nov-09 1:16
souidi abderrahman30-Nov-09 1:16 
GeneralRe: Setting DataGridView ColumnHeader text Pin
kanchoette30-Nov-09 1:27
kanchoette30-Nov-09 1:27 
QuestionHow to make screen become gray/dark slowly? Pin
daveice29-Nov-09 20:23
daveice29-Nov-09 20:23 
AnswerRe: How to make screen become gray/dark slowly? Pin
Abhishek Sur29-Nov-09 21:06
professionalAbhishek Sur29-Nov-09 21:06 
AnswerRe: How to make screen become gray/dark slowly? Pin
J a a n s29-Nov-09 21:16
professionalJ a a n s29-Nov-09 21:16 
GeneralRe: How to make screen become gray/dark slowly? Pin
Abhishek Sur29-Nov-09 21:37
professionalAbhishek Sur29-Nov-09 21:37 
GeneralRe: How to make screen become gray/dark slowly? Pin
dan!sh 29-Nov-09 23:19
professional dan!sh 29-Nov-09 23:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.