Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ekrem Altintas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s = ...

int index = s.indexOf("...");
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Ekrem Altintas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tahnks. It has worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic