I'm trying to split and sort this long weblog string:
"140.184.37.105 - - [08/Aug/2001:21:06:36 -0300] "GET /~csc226/outline.htm HTTP/1.0" 200 9748 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.73 [en] (WinNT; U)""
My current code definitely doesn't work and I'm trying to figure out any ways to improve my code or use a different method of solving this problem. It obtains an array of many weblog entries, including the one above. I'm mainly trying to figure out how to sort the array to show the date as August 8, the ip address as 140.184.37.105, etc.
void getString(int i)
{
return bin[i];
}
public void getIP(int i)
{
int IPlength = bin[i].length() - bin[i].indexOf("- -");
String IP = bin[i].substring(0, bin[i].length()-IPlength);
}
void getDate(int i)
{
String Date = bin[i].substring(bin[i].indexOf('['), bin[i].indexOf(']'));
}
void getPage(int i)
{
String Page = bin[i].substring(bin[i].indexOf("GET"), bin[i].indexOf("1.0"));
}
I'm sorry if this question is inconsiderate but I'm new and don't know how to approach or solve this problem.
The result should look something like this:
ip Address: 140.184.37.105
Date and Time enclosed in brackets: [08/Aug/2001:21:06:36 -0300]
Page Requested in quotes: "GET /~csc226/outline.htm HTTP/1.0"
HTTP Status Code returned to the client (200= successful): 200