wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes finding a particular string in string type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "finding a particular string in string type" Watch "finding a particular string in string type" New topic
Author

finding a particular string in string type

kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
Hi All,
I need to find whether a particular string like "kundan" exist in a line or not. What is the best way to solve this in java?
Can somebody give a example.
Thanks and regards,
kundan


SCJP1.4,SCBCD,SCEA,CNA
Failures are practice shoots for success.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3502
    
  13
String.indexOf()


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Have you never tried the contains method in String? It only works in J5 and 6, however.
Rakesh Kumar
Ranch Hand

Joined: May 30, 2006
Posts: 63
welcome to javaranch discussion boards

let 's' be the the string coressponding theline,then
s.indexOf("kundan") will give the index of 1st occurence of the string"kundan".

cheers
sujith
Parambir Singh
Ranch Hand

Joined: Sep 05, 2004
Posts: 40

And if "kundan" is not present, it will return -1.


SCJP, SCMAD
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Advanced? I think not. Moving to Java in General (Beginner).


[Jess in Action][AskingGoodQuestions]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: finding a particular string in string type