我正在写这个小程序从文本文件中提取任意数量的电子邮件地址。我收到两个错误,“使用未分配的本地变量”。我不知道为什么。简单的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