• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

string find/search code in java  RSS feed

 
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 ]
 
(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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!