• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finding a particular string in string type

 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String.indexOf()
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you never tried the contains method in String? It only works in J5 and 6, however.
 
Rakesh Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if "kundan" is not present, it will return -1.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Advanced? I think not. Moving to Java in General (Beginner).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic