code doesnt continue reading from where it left off

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 5
Reputation: x2012 is an unknown quantity at this point 
Solved Threads: 0
x2012 x2012 is offline Offline
Newbie Poster

code doesnt continue reading from where it left off

 
0
  #1
Jan 6th, 2007
Hi, im writing a piece of code that reads an HTML source code file. The code is meant to read the HTML and pick out stock symbols. It seems to work fine but as soon as it finds the first stock ticker, the program stops. Ideally, it should find all the stock tickers (There can be upto 25 symbols in the html code).
What am i doing wrong? I would appreciate any help. My C# code is posted below:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
namespace pinksheets2
{
class Program
{
static void Main(string[] args)
{
System.IO.StreamReader file = new System.IO.StreamReader("c:\\dlist.txt");
// dump streamreader contents to string
string strContent = file.ReadToEnd();

Console.WriteLine(strContent);
// search string
string startStr = "../quote/quote.jsp?symbol=";
// end string
String endStr = ">";
int startIndex;
int endIndex;
string record = null;

String str = null;
while ((record = strContent) != null)
{
startIndex = record.IndexOf(startStr);
if (startIndex != -1)
{
endIndex = record.IndexOf(endStr, startIndex);
 
if (endIndex != -1)
{
int length = endIndex - startIndex;
str = record.Substring(startIndex, length);
Console.WriteLine(str);
string words2 = str;
string[] split = str.Split(new Char[] { ' ', ',', '.', ':', '=', '>' });
Console.WriteLine("symbol is:" + split[4]);
Console.Read();


}
}
}
 
 
}
}
}


I can post the html code too if needed.

TIA
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 45
Reputation: _r0ckbaer is an unknown quantity at this point 
Solved Threads: 7
_r0ckbaer's Avatar
_r0ckbaer _r0ckbaer is offline Offline
Light Poster

Re: code doesnt continue reading from where it left off

 
0
  #2
Jan 6th, 2007
Console.Read();
It's waiting for the user to press the ENTER key here, so it stops
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 5
Reputation: x2012 is an unknown quantity at this point 
Solved Threads: 0
x2012 x2012 is offline Offline
Newbie Poster

Re: code doesnt continue reading from where it left off

 
0
  #3
Jan 6th, 2007
Originally Posted by _r0ckbaer View Post
It's waiting for the user to press the ENTER key here, so it stops
thanks for the comment. i didnt realize that.

even if i dont use console.read() , the real problem is that the code just goes back to the start of the html source code whereas i want it to continue reading the html code from where it left off.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 39
Reputation: Maidomax is an unknown quantity at this point 
Solved Threads: 0
Maidomax Maidomax is offline Offline
Light Poster

Re: code doesnt continue reading from where it left off

 
0
  #4
Jan 7th, 2007
It wouldn't hurt if you posted the HTML as well.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 5
Reputation: x2012 is an unknown quantity at this point 
Solved Threads: 0
x2012 x2012 is offline Offline
Newbie Poster

Re: code doesnt continue reading from where it left off

 
0
  #5
Jan 7th, 2007
here's the part of the HTML code im interested in

<TR BGCOLOR="#ffffff" BORDERCOLOR="#FDEFF9">
<TD NOWRAP>A.B. WATLEY GROUP, INC.</td>
<TD NOWRAP>PS</td>
<TD> Com ($0.001)</td>
<TD NOWRAP><a href=../quote/quote.jsp?symbol=ABWG>ABWG</a></td>

</tr>



<TR BGCOLOR="#FDEFF9" BORDERCOLOR="#FDEFF9">
<TD NOWRAP>A.G. MEDIA GROUP, INC.</td>
<TD NOWRAP>PS</td>
<TD> Com ($0.001)</td>
<TD NOWRAP><a href=../quote/quote.jsp?symbol=AMGJ>AMGJ</a></td>

</tr>



<TR BGCOLOR="#ffffff" BORDERCOLOR="#FDEFF9">
<TD NOWRAP>A21, INC.</td>
<TD NOWRAP>PS/OTC BB</td>
<TD> Com ($0.001)</td>
<TD NOWRAP><a href=../quote/quote.jsp?symbol=ATWO>ATWO</a></td>

</tr>



<TR BGCOLOR="#FDEFF9" BORDERCOLOR="#FDEFF9">
<TD NOWRAP>AAA ENERGY, INC.</td>
<TD NOWRAP>PS/OTC BB</td>
<TD> Com ($0.001)</td>
<TD NOWRAP><a href=../quote/quote.jsp?symbol=AAAE>AAAE</a></td>
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 45
Reputation: _r0ckbaer is an unknown quantity at this point 
Solved Threads: 7
_r0ckbaer's Avatar
_r0ckbaer _r0ckbaer is offline Offline
Light Poster

Re: code doesnt continue reading from where it left off

 
0
  #6
Jan 9th, 2007
I would do this via regex, here's some example:

  1. static void Main(string[] args)
  2. {
  3. const string theRegexString = "quote\\.jsp\\?symbol=([^=>]+)\\s*>";
  4. Regex regex = new Regex(theRegexString, RegexOptions.Compiled);
  5.  
  6. using (StreamReader inFile = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\test.txt"))
  7. {
  8. string contents = inFile.ReadToEnd();
  9.  
  10. MatchCollection matches = regex.Matches(contents);
  11. foreach (Match match in matches)
  12. {
  13. Console.WriteLine(match.Groups[1]);
  14. }
  15. }
  16.  
  17. Console.ReadKey();
  18. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC