1)Document 126, Exprot List 04-15.xls owned by jackzhang was printed on printserver1 via port IP_192.168.0.1. Size in bytes: 46205; pages printed: 2 For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.2)1)Document 123,monthly report.doc owned by Tomliu was printed on printserver2 via port IP_192.168.0.1. Size in bytes: 46267; pages printed: 4 For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.上面的两条message,大家应该很熟悉,就是print Eventlog里的message,现在我想分析这串字符,把打印文件名,打印用户,打印服务器名,打印字节大小,IP地址,打印页数读出来,大家有什么好方法?谁能帮我实现呀?
Regex re = new Regex(strMatch);
Match m = re.Match(strText);
if(m.Success)
{
打印文件名 = m.Groups[1].ToString();
打印用户 = m.Groups[2].ToString();
打印服务器名 = m.Groups[3].ToString();
打印字节大小 = m.Groups[4].ToString();
IP地址 = m.Groups[5].ToString();
打印页数 = m.Groups[6].ToString();
}
using System.Diagnostics;
using System.Text;public class printlog
{
public static void Main(String[] args)
{
string strText = "Document 126, Exprot List 04-15.xls owned by jackzhang was printed on printserver1 via port IP_192.168.0.1. Size in bytes: 46205; pages printed: 2";
string PrintDocName,PrintUser,PrintServerName,PrintByte,PrintIp,PrintPages;
string strMatch = @"^Document (\d+),.*(.+) owned by (.+) was printed on (.*) via port IP_(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\. Size in bytes: (\d+); pages printed: (\d+)";
Regex re = new Regex(strMatch);
Match m = re.Match(strText);
if(m.Success)
{
PrintDocName = m.Groups[1].ToString();
PrintUser = m.Groups[2].ToString();
PrintServerName = m.Groups[3].ToString();
PrintByte = m.Groups[4].ToString();
PrintIp = m.Groups[5].ToString();
PrintPages = m.Groups[6].ToString();
}
Console.WriteLine(PrintDocName);
Console.WriteLine(PrintUser);
Console.WriteLine(PrintServerName);
Console.WriteLine(PrintByte);
Console.WriteLine(PrintIp);
Console.WriteLine(PrintPages);
}
}