• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

parse String

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using JDK 1.4 and would like to know a simpe way to check if a String contains part of another String.

For example, how can I tell if the String "and" is found anywhere in the String "Stand"?

Is there a method on the String class for this? If it involves regular expressions, what would that be?

Thanks.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try "indexOf"
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you may unaware of the comprehensive API documentation available online. The documentation (cleverly named "Javadocs") covers the methods and properties of all the core Java classes & interfaces. For exampleclick here to see the documentation for the String class
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
indexOf looks like it is teh way to go.

I am familiar with the javadoc. I was just looking for advice on which particular String method to use. The javadoc did not provide enough information for me to make the best decision on which of the many methods to use.

Thanks for the comments.
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andy,
You can use the folowing example:
 
Santosh Pasupuleti
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But, the above code will work if you are searching for "AND" in "stand".
indexOf will return -1 (not found) if there is case mismatch.

So, you will have to introduce the toLowerCase() or toUpperCase() methods of String class.

Take a look at the following code:
 
I found some pretty shells, some sea glass and this lovely tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic