• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringTokenizer

 
Azz Romaysa
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Azz Romaysa
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic