aspose file tools*
The moose likes Beginning Java and the fly likes string find/search code in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string find/search code in java" Watch "string find/search code in java" New topic
Author

string find/search code in java

auvrm papu
Ranch Hand

Joined: Sep 01, 2005
Posts: 105
I have
String myStr = "[0,45]";

I want to set the min and max variables as below :

String min = "0"
String max= "45"

how to do that?

thanks.
auvrm papu
Ranch Hand

Joined: Sep 01, 2005
Posts: 105
never mind the above...

given
String myStr = "0,45"

split it with min and max..thanks
[ March 21, 2007: Message edited by: Laxi Rara ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, there must be about a dozen ways to do this one. Here are a few. Take a look at the JavaDoc for the classes mentioned and see if any of them sounds fun. These are probably in order from least learning curve to the most, depending on what you already know ...

String.indexOf to find the comma and String.substring the left and right parts.

String.split on a comma delimiter

StringTokenizer with a comma delimiter

Scanner with a comma delimiter - has the advantage that it can convert to int as you pull parts out of the string.

Regular expressions. See Pattern and Matcher.

Let us know what you choose!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string find/search code in java