• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Getting a word from a particular location in a text file

 
Greenhorn
Posts: 2
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, I am currently working on a project where I have to use two text files, one text file contains a script of a movie called "The Truman Show". The other txt file contains 6 sentences (statements) with fill in the blanks, I have to find the missing word from the Script.txt file and put it instead of the blank which is denoted by '___'.

So far I am able to use a KMP search algorithm to find the missing word but I am not sure how to get the missing word and put it instead of the '___'. I know I am supposed to use a regex function called replaceAll(), but I am using a bufferedReader to scan both txt files and there are two pointers i and j. i and j stop whenever there is a mismatch. So currently i and j are stopped and one of them is at the beginning of the missing word and the other one is at the underscore "_".



Should I use an ArrayList to get the word? I am sort of confused. Your help would be much appreciated.
Thanks in advance.
Farhan Hasan
 
Rancher
Posts: 4893
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the Current_Statement object is a String then the String class's replaceAll method returns a new String that needs to be saved in a variable.
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your variable names are not very Java-like.  Take a look at NamingConventions (that's a link) to learn how to name things in Java.
 
This will take every ounce of my mental strength! All for a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic