Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

To retrive a particular line from the file  RSS feed

 
Anisha Sringeshwar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I am anisha. Am trying to retreive a particular line (the line which has my search keyword) from the text file.
let me brief it up. now suppose am searching for a string in a textfile and i would like to retrive only that particular sentence from the file where the keyword is present. (sentence in the sense the words between the 2 full stops).
I came up with an idea for it. first am going to retrive the index of the search string, using that index as the starting index am going to retrive the full stop following the search string. now to retrive the index of the full stop before the search string am going to run a loop and get the index of every full stop from beginning untill that index becomes greater than the index of the search string. now using substring i can retreive the sentence.
But somehow am not able to implement it properly. Below is the code which i have tried.


Can anyone please help me to get a solution for this.. please..
Thanking you in advance.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, you want a sentence and not a line, right?

What happens when you run what you have so far?
 
Anisha Sringeshwar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your reply sir
Yes am trying to retrieve only the sentence not the whole line. Actually i got it using scanner. I did it in this way. Its working.
It was such a simple thing but i had made it complicated and was scartching my head

Thanking you again.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anisha Sringeshwar wrote:Thanks a lot for your reply sir
Actually i got it using scanner.


Glad to hear it!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!