wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How to find a word in a text file? (2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to find a word in a text file? (2)" Watch "How to find a word in a text file? (2)" New topic
Author

How to find a word in a text file? (2)

Ekrem Altintas
Greenhorn

Joined: Dec 20, 2005
Posts: 14
hellohowareyouhellohowareyou

For example, I want to find "hello" words in the text above. There is not spaces in this text.What can I do?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
String s = ...

int index = s.indexOf("...");
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Note that there is also an indexOf(str, fromIndex).

So if the first occurrence is at index 7, for example, then you could find the next occurrence using indexOf("...", 8).


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Ekrem Altintas
Greenhorn

Joined: Dec 20, 2005
Posts: 14
Tahnks. It has worked
 
jQuery in Action, 2nd edition
 
subject: How to find a word in a text file? (2)