1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| using System;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s =
@"10:41:28 Warning: String with lot of spaces file:C:/test/fdsfsdfsdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd/sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
10:41:29 Warning: File has moved from BzID=1233&to=cp&Nav=0&S=0&L=1&ID=11002 to file:C:\blah\test\blablaf=1&BzID=1233&to=cp&Nav=0&LangID=1&s=0&ID=11002
10:41:31 Errors: veryslonggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggString1ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss";
MatchCollection matches = Regex.Matches(s, @"^(?<timestamp>\d{2}:\d{2}:\d{2})\s+(?<type>[^:]+):\s+(?<msg>.*)$", RegexOptions.Multiline);
Info[] infos = new Info[matches.Count];
for (int i = 0; i < matches.Count; i++)
{
infos[i] = new Info(matches[i].Groups["timestamp"].Value, matches[i].Groups["type"].Value, matches[i].Groups["msg"].Value);
}
}
}
public class Info
{
public TimeSpan TimeStamp { get; private set; }
public string MessageType { get; private set; }
public string Message { get; private set; }
public Info(string timeStamp, string messageType, string message)
{
this.TimeStamp = TimeSpan.Parse(timeStamp);
this.MessageType = messageType;
this.Message = message;
}
}
} |
Partager