Without knowing more about your data and what you want to do with it, I would suggest a regex. Assuming you have already broken your text into lines:
public static Regex regex = new Regex("(?<IPAddr>\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}).*?\\[(?<Date>.*?)\\] (?<Action>.*)",
RegexOptions.CultureInvariant | RegexOptions.Compiled);
...
string InputText = "172.21.128.221 - - [22/Jan/2013:16:00:00 +0900] \"GET /iv/iv_1_5_1/js/annt/con_annt_resize.js?v=200711220 HTTP/1.0\" 304 -";
Match m = regex.Match(InputText);
if (m.Groups["IPAddr"].Value == Filter.text)
{
string date = m.Groups["Date"].Value;
string action = m.Groups["Action"].Value;
...
}
"Oh. I'm sorry. Here.
Given that I have this data:
172.21.128.221 - - [22/Jan/2013:16:00:00 +0900] "GET /iv/iv_1_5_1/js/annt/con_annt_resize.js?v=200711220 HTTP/1.0" 304 -
10.144.100.63 - - [22/Jan/2013:16:00:00 +0900] "GET /iv/iv_lite/files/iv.key HTTP/1.0" 200 114
10.144.100.64 - - [22/Jan/2013:16:00:00 +0900] "POST /iv/iv_lite/files/iv.key HTTP/1.0" 200 114
and I would like to extract the data with the Date: [22/Jan/2013:16:00:00 +0900] and the Method: GET
How would I make my condition?"
Try:
(?<IPAddr>\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}).*?\\[(?<Date>.*?)\\]\\s\"(?<Method>\\w+)(?<Action>.*)
You will then get a Group called "Method" added to your Match
Get a copy of
Expresso [
^] - it's free, and it examines and generates Regular expressions.