This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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: 3720
    
  16
String.indexOf()


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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: 24187
    
  34

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


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finding a particular string in string type