• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding poistion (Line Number) of text in a given File.

 
Sneha Teck
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have to find the Line Number of a 'text' from within a given file.

The file name and the 'text' is available.

Appreciate any help in achieving this .


Thanks.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are some pointers:

  • Example: Read a text file line by line
  • You might want to use class java.io.LineNumberReader (lookup the API documentation)
  • There are methods in class String to find out if a string contains a certain text (lookup the API documentation)

  •  
    Monika Joshi
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    Here is the pseudocode. This should work.

    [Jesper Young: solution deleted]

    Regards,
    Minakshi
     
    Jesper de Jong
    Java Cowboy
    Saloon Keeper
    Posts: 15216
    36
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Minakshi, welcome to JavaRanch.

    I deleted your solution, because on JavaRanch we have a policy that we want to encourage people to learn - giving people complete solutions to their programming assignments does not help people learn. So, thank you for your contribution, but please don't post complete solutions. (And a tip: UseCodeTags when you post source code).
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic