• Post Reply Bookmark Topic Watch Topic
  • New Topic

get position of words in a file  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i find in a file the positions of a word?I am trying to make an index for a file so i read the file and i save all the deifferent words in an array of string
example.
Hello everybody i
am new in the forum hello
how i will understand that the string hello is in the first line in first character and in the second line in the 21 character
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can read lines of a file using a BufferedReader wrapped around a FileReader.
You will have to decide how to separate out words within a line; a first (rather naive) approach might involve using String.split(" ") on the lines you read from the file.
Once you have that working you might start to think how to deal with numbers, punctuation marks, word capitalization etc.
 
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why do you particularly want to save things in an array? That sounds as if you are trying to work out the implementation before the task. Write down carefully on a piece of paper how you would do that exercise by hand. When you have done that, consider how you would tell a computer to do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!