File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to find a word in a text file? (2)
 
Similar Threads
Trying to extract text portion of select statement entry
Difference between Abstract Class and Interface, Which scenarios we are using both?
jdbc text drivers
JTextPane vs AWT TextArea
File constructor