Monday, February 25, 2013

Extract Email from any Web Site using C#.net

2) How to Extract Email from the Web page:
        public string[] Extract_Emails(string source)
        {
            string[] Email_List = new string[0];
            Regex r = new Regex(@"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}"
               RegexOptions.IgnoreCase);        
             Match m;
             //Searching for the text that matches the above regular 
              expression(which only matches email addresses)
            for (m = r.Match(source); m.Success; m = m.NextMatch())
            {
                //This section here demonstartes Dynamic arrays
                if (m.Value.Length > 0)
                {
  //Resize the array Email_List by incrementing it by 1, to save the next result                   
if (Array.IndexOf(Email_List, m.Value) < 0)
                    {
                        Array.Resize(ref Email_List, Email_List.Length +
                        Email_List[Email_List.Length - 1] = m.Value;
                    }
                }
            } 
            return Email_List;
        }

No comments:

Post a Comment