• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

get position of words in a file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic