Beispiel #1
0
        /*private string CPParse(string data)
         * {
         *  Regex myregex = new Regex("\\d{5}");
         *  var matches = myregex.Matches;
         *
         * }
         */
        private void button1_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();

            System.Net.WebRequest obj = System.Net.HttpWebRequest.Create("http://www.codespostaux.com/home/r.php?q=" + textBox1.Text + "&Pays=FR");

            System.Net.WebResponse objResponse = obj.GetResponse();

            System.IO.StreamReader stream = null;

            try
            {
                stream = new System.IO.StreamReader(objResponse.GetResponseStream());

                string cleanedtext = HtmlSanitizer.getText(stream.ReadToEnd());
                textBox2.Text = cleanedtext;

                Regex cpregex = new Regex(@"(\d{5}?)([A-Z\s]*)");
                //Regex villeregex = new Regex(@"[A-Z\s]*");

                var cpmatches = cpregex.Matches(cleanedtext);
                //var villematches = villeregex.Matches(cleanedtext);

                //Console.Write(cleanedtext);

                MatchCollection matches = cpregex.Matches(cleanedtext);

                for (int i = 0; i != matches.Count; ++i)
                {
                    Console.Write(matches[i].Groups["1"].Value + " - " + matches[i].Groups["2"].Value + "\n");
                }
            }


            catch { }

            finally
            {
                if (objResponse != null)
                {
                    objResponse.Close();
                }
            }
        }