Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string find/search code in java

 
auvrm papu
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic