2011-02-15 56 views
-2
  if(!string.IsNullOrEmpty(result)) 
      { 
       Coderbuddy.ExtractEmails helper = new Coderbuddy.ExtractEmails(result); 
       EmailsList = helper.Extract_Emails; 

      } 



using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Text.RegularExpressions; 
namespace Coderbuddy 
{ 
    public class ExtractEmails 
    { 
     private string s; 
     public ExtractEmails(string Text2Scrape) 
     { 
      this.s = Text2Scrape; 
     } 
     public string[] Extract_Emails() 
     { 
      string[] Email_List = new string[0]; 
      Regex r = new Regex(@"[A-Z0-9._%+-][email protected][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(s); 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 
        Array.Resize(ref Email_List, Email_List.Length + 1); 
        Email_List[Email_List.Length - 1] = m.Value; 
       } 
      } 
      return Email_List; 
     } 
    } 
} 
+2

請寫下一個問題。不要只是轉儲代碼。 – 2011-02-15 08:29:10

回答

3

儘管我討厭回答(因此鼓勵)沒有問題的帖子,但問題是您缺少問題括號EmailsList = helper.Extract_Emails後面的圓括號表示它認爲您需要函數Extract_Emails本身,而不是調用該函數。

如果你使它EmailsList = helper.Extract_Emails();它應該修復編譯器錯誤。

相關問題