Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey guys, wonder if you can help me with a issue with this piece of code
private void button7_Click(object sender, EventArgs e)
       {
           if (checkBox5.Checked == true)
           {

               Navigate("http://www.drugrunners.net/GroupSetup.cfm?Open=A,I&Sort=DrugValue&SortOrder=DESC", webBrowser3);
               string html = webBrowser3.DocumentText;
               string[] Target = Regex.Split(html, "<td class=\"tinytight\" width=\"100\">");
               for (int i = 1; i < Target.Length; i++)
               {
                   MessageBox.Show("New Person");
                   string[] Values = Regex.Split(Target[i],  "align=\"right\">");
                   for(int l = 1; l < Values.Length; l++)
                   {
                       if (l == 6)
                       {
                           int Troops = int.Parse(Regex.Split(Values[l], "/td>")[0]);
                           if (Troops < 30000)
                           {
                               MessageBox.Show("Confirmed");
                           }
                       }



i am informed that is is
int Troops = int.Parse(Regex.Split(Values[l], "/td>")[0]);

that is throwing the error

Many thanks in advance
Posted

I think
Regex.Split(Values[l], "/td>")[0]

Is not a String. int.Parse(); need string parameter.
 
Share this answer
 
Instead of parsing some specific HTML elements with Regex, it would be better to use some general approach and parse HTML. You will be able to find some open-source parsers, for example: http://www.majestic12.co.uk/projects/html_parser.php[^].

It would be the best if HTML was well-formed XML which you could easily parse with any of the XML parsers which come with .NET FCL, but, unfortunately, this is not always the case.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900