Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

finding a particular string in string type  RSS feed

 
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
Posts: 55292
156
  • 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
Sheriff
Posts: 24217
38
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).
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!