private void button1_Click(object sender, EventArgs e) //点击获取网页邮箱 { if (textBox1.Text.Trim() != "") { HttpWebRequest wrst = (HttpWebRequest)WebRequest.Create(textBox1.Text); //创建对网页内容(源码)的访问请求(文本框1输入网址) HttpWebResponse wrpse = (HttpWebResponse)wrst.GetResponse(); //反馈网页请求 Stream s = wrpse.GetResponseStream();//将反馈的信息存入Stream流 StreamReader sr = new StreamReader(s, Encoding.Default);//将Stream流里的内容以Encoding.Default编码方式存到第二个流sr里面 string x = sr.ReadToEnd();//定义一个变量x来接收网页源码 // MatchCollection 通过不停的替换将正则表达式模式应用于输入字符串所找到的成功匹配的集合 MatchCollection mc = Regex.Matches(x, @"[a-zA-Z0-9_-.]+@w+(.w+)+");//将源码按邮箱正则匹配存到区域集合mc里面 StringBuilder sb = new StringBuilder(); //表示可变字符串 foreach (Match m in mc) //开始遍历 { sb.AppendLine(m.Value);//找到匹配项,并整合 (将所找到的字符存到sb里面)Append附加 } textBox2.Text = sb.ToString(); } else { MessageBox.Show("请输入正确的网址"); } }
////另存为
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "文本文件|*.txt"; DialogResult dr= saveFileDialog1.ShowDialog(); if(dr==DialogResult.OK) { string file = saveFileDialog1.FileName; StreamWriter sw = new StreamWriter(file); sw.Write(textBox2.Text); sw.Close(); } }