Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

to search a word  RSS feed

 
N SRao
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have to search a word in the file.
After finding the word i have to append a new line after that word. please give me the solution ASAP.
regards,
srao
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you should use a StringBuffer and put the content of the file in it. Then with the method indexOf(String s) you can retrieve the position in the String where the word you are searching for is. Then you use the method insert(int i, String s) to insert your new line.
Let's say you are searching for the word "Start", then...

There are other solutions (RandomAccessFile, ...) but this one, IMO, is the simplest one.
Moreover, you shouldn't post the same question several times.
Please remove your other post about the same topic.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!