我尝试使用C#实现IMAP。
我有以下功能:
public int MailUnreadCount()
{
imapSw.WriteLine("$ STATUS INBOX (unseen)");
imapSw.Flush();
string res = Response();
Match m = Regex.Match(res, "[0-9]*[0-9]");
return Convert.ToInt32(m.ToString());
}
然后我上线了:
return Convert.ToInt32(m.ToString());
以下错误说明:
Exception thrown: 'System.FormatException' in mscorlib.dll
任何人都知道这是什么问题?
感谢。
答案 0 :(得分:0)
你应该使用:
Match m = Regex.Match(res, "[0-9]*[0-9]");
if (m.Success)
{
return Convert.ToInt32(m.Value);
}