I`m using the code below to search for the data in a web page and return the data to da datagridview.
When I use it with a web page that has many rows like 100, some time it will return a buggy line like this: CaucaiaCE
and should be only Caucaia
Why it happens only in 2 lines out of 100?
this is the html I`m searching http://pastie.org/8220836
{
int i = 0;
Match matchLogradouro = Regex.Match(pagina, "<td width=\"268\" style=\"padding: 2px\">(.*)</td>");
Match matchBairroCidade = Regex.Match(pagina, "<td width=\"140\" style=\"padding: 2px\">(.*)</td>");
Match matchEstado = Regex.Match(pagina, "<td width=\"25\" style=\"padding: 2px\">([A-Z]{2})</td>");
Match matchCep = Regex.Match(pagina, "<td width=\"65\" style=\"padding: 2px\">(.*)</td>");
int z = Regex.Matches(pagina, "detalharCep").Count;
while (z > i -1)
{
dataGridView1.Rows.Add(matchLogradouro.Groups[1].Value);
matchLogradouro = matchLogradouro.NextMatch();
dataGridView1.Rows[i].Cells[1].Value = matchBairroCidade.Groups[1].Value;
matchBairroCidade = matchBairroCidade.NextMatch();
dataGridView1.Rows[i].Cells[2].Value = matchBairroCidade.Groups[1].Value;
matchBairroCidade = matchBairroCidade.NextMatch();
dataGridView1.Rows[i].Cells[3].Value = matchEstado.Groups[1].Value;
matchEstado = matchEstado.NextMatch();
dataGridView1.Rows[i].Cells[4].Value = matchCep.Groups[1].Value;
matchCep = matchCep.NextMatch();
i++;
}
}