IO problem
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   qayyum_ghanty
Posted On:   Tuesday, October 8, 2002 02:10 AM

Hi,
i am reading lines from a file.Then i break a line into tokens and assign each token in a variable as i will place them in a database. Each line has the following format:

www.jguru.com [20:23:12] "Get/ Http 1.0" 202 2160


I used stringtokenizer.
The problem is that i want to put the "Get/ Http 1.0" in a single token.Right now it breaks it as:


"Get/


Http


1.0"


Any idea how to do this?
Thanks

Re: IO problem

Posted By:   eimi_nos  
Posted On:   Tuesday, October 8, 2002 07:08 AM

I prefer primitive solution:

String test = "www.jguru.com [20:23:12] "Get/ Http 1.0" 202 2160".trim();
ArrayList list = new ArrayList();
int n=0, len = test.length();
while((n=test.indexOf('u0020'))!=-1){ // i.e., ' '
list.add(test.substring(0,n));
test = test.substring(n+1,len).trim();
len=test.length();
if(test.charAt(0)=='u0022'){ // i.e., '"'
int i=0;
for(i=0;i if(1<=i && test.charAt(i)=='u0022') {
list.add(test.substring(0,i+1));
test=test.substring(i+1,len).trim();
len=test.length();
}
}
}

}
if(test.length() !=0) list.add(test);
String[] result = new String[list.size()];
for(int q=0;q if(list.get(q) instanceof String) result[q]=(String)list.get(q);
else throw new ClassCastException();
}

Re: IO problem

Posted By:   Lasse_Koskela  
Posted On:   Tuesday, October 8, 2002 05:20 AM

If you can trust that the "GET/" and "HTTP 1.0" are always the 3rd and 4th token, you could just append them together. That would be the easiest fix in my opinion.
About | Sitemap | Contact