0

Hi!

First post! :)

I have some problem with finding a number in a specific row in a HTML document i'm fetching. I dont really know much of Regexp, but i guess thats how i will do it?

The code i'm using

StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), Encoding.ASCII);
                int countLines = 0;

                while(!sr.EndOfStream())
                {
                        //Find: 		<td valign="top" align="right" >124379</td>
                      //sr.ReadLine(); //That one should hold the number.
                        
                       
                }

I want to parse out 124379 from:
<td valign="top" align="right" >124379</td>

That number can differ (not always 6 chars). Anyone knows how to do it?

Thanks
/m

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by zykostar
0

Finding examples of the regular expression library in C# is easy, so I'll leave that to you. The regular expression you want might be something like this:

">\s*\d+\s*<"

What this does is look for any number with one or more digits (+\d), surrounded by > on the left side and < on the right side with optional whitespace between. It'll pick up any HTML element value that's just a number, so if you want to match just table data elements, you can be more specific:

"<td.*>\s*\d+\s*</td>"

Now the regular expression matches an opening tag of "<td" followed by any number of attributes, the value string as before, and also the closing tag of "/td>.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.