我正在寫這個小程序從文本文件中提取任意數量的電子郵件地址。我收到兩個錯誤,「使用未分配的本地變量」。我不知道爲什麼。簡單的C#錯誤幫助
static void Main(string[] args)
{
string InputPath = @"C:\Temp\excel.txt";
string OutputPath = @"C:\Temp\emails.txt";
string EmailRegex = @"^(?:[a-zA-Z0-9_'^&/+-])+(?:\.(?:[a-zA-Z0-9_'^&/+-])+)*@(?:(?:\[?(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\.){3}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\]?)|(?:[a-zA-Z0-9-]+\.)+(?:[a-zA-Z]){2,}\.?)$";
string Text = String.Empty;
StringBuilder Output;
List<string> Emails;
using (TextReader tr = new StreamReader(InputPath))
{
Text = tr.ReadToEnd();
}
MatchCollection Matches = Regex.Matches(Text,EmailRegex);
foreach (Match m in Matches)
{
Emails.Add(m.ToString().Trim()); // one error is here
}
foreach (String s in Emails)
{
Output.Append(s + ","); // the other error is here
}
using (TextWriter tw = new StreamWriter(OutputPath))
{
tw.Write(Output.ToString());
}
}
對不起格式化......我有點時間緊迫!
編輯:WOW。我是一個白癡 - 一定是因爲我時間緊迫!!!!
你想讓我們爲你「懲罰」你是個「白癡?」嗎? ;)順便說一句,按下時間,慢下來!這是你真正的錯誤。 (和不,你是不是一個白癡,我們都犯了這個錯誤至少一次) – 2009-07-17 13:31:43