aspose file tools*
The moose likes Servlets and the fly likes StringTokenizer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "StringTokenizer" Watch "StringTokenizer" New topic
Author

StringTokenizer

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hi,

I've a query:
.
.
.
"HAVING leeftijd BETWEEN "+MinAge+" AND "+MaxAge+"+
.
.
.

I've a String age. I get this String from a jsp as a parameter.
String _age = request.getParameter("age");

The age String can be: "0 - 5", "6 - 12" or "13 - 18" where the 0,6 and 13 are the minAge, and 5, 12 or 18 are the maxAge.

I rtied to use a StringTokenizer to get the minAge and maxAge, but it doesn't seems to work.
My question is how can I get the minAge and the maxAge from the selected intervall.

This is my code:
StringTokenizer st = new StringTokenizer(_age.replaceAll("-",""));
while (st.hasMoreTokens()) {
System.out.println("####### The min/max age is : "+ st.nextToken());
}
and this is an example of what I get:
####### The min/max age is : 6
####### The min/max age is : 12

But how can I get each value as a seprate variable?

Thanks
Abu Romaysa
[ January 03, 2005: Message edited by: Azz Romaysa ]
sureshbabu
Greenhorn

Joined: Dec 09, 2004
Posts: 8
Try this, it works

String _age="6 - 12";
StringTokenizer st = new StringTokenizer(_age.replace('-',' '));
while (st.hasMoreTokens()) {
System.out.println("####### The min/max age is : "+ st.nextToken());
}
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Thanks sureshbabu,

I know that that code works. But what I want is to get the 6 and 12 in as seprate variables.
So when I'll call 'maxAge' then it should ben return a '12', and when I'll cal 'minAge' then it should ben return '6'.

Any idea's???

Thanks
Abu Romaysa
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Sure, and you don't need to do the fairly expensive character replacement either.

You'll need to do quite a bit of protection around these to prevent parse errors but, this should do it for you. A better approach would be to have seperate entry field for each.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hi Carl,

Thank you very very much... It works great..
Now I'm able to take the min and the max to execute my query.

Thanks again.

Abu Romaysa
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringTokenizer