0

I'm writing a duplicate remover for BibTex. The books are listed in that form:

@Book{abramowitz+stegun,
    author =    "Milton Abramowitz and Irene A. Stegun",
    title =     "Handbook of Mathematical Functions with
                 Formulas, Graphs, and Mathematical Tables",
    publisher = "Dover",
    year =      1964,
    address =   "New York",
    edition =   "ninth Dover printing, tenth GPO printing"
}^

What I have done is to read the data from external txt file, and Tokenize them after each book.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gotowy;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 *
 * @author Adam
 */
public class DuplicateFinder {
    void deleteDuplicates(File filename) throws IOException{       
    BufferedReader reader = new BufferedReader(new FileReader(filename));

     String textLine = reader.readLine();
     String dodaj = "";
  do {
    //System.out.println(textLine);

    textLine = reader.readLine();
    dodaj = dodaj + textLine;
  } while(textLine != null);

  reader.close();
        String books;
        books = dodaj;
        System.out.println(books);
        String delimiter = "^";
     StringTokenizer st = new StringTokenizer(books,delimiter);
     int liczbaTokenow = st.countTokens();
     System.out.println(liczbaTokenow);
     System.out.println(st);


    books.substring(books.indexOf("title") + 3 , books.length());


    // while (st.hasMoreTokens()) {
       //  System.out.println(st.nextToken()+"xDDDDDDDDDDDD");
     //}

}
}

And now I need help with get the substring of the title after every "title" keyword (in each token!!) in my list and compare them. Any ideas? Thx in advance! :)

2 Answers2

0

I assume that the title will always be within the quotation marks. The problem will then be the same as here, except that the parenthesis should be replaced by quotation marks. So it will be something like:

public String getTitle(String s){
  s = s.substring(s.indexOf("\"") + 1);
  s = s.substring(0, s.indexOf("\""));
  return s;}

Your while-loop would then be:

while (st.hasMoreTokens()) {
String item = st.nextToken();
String substringWithTitle = item.substring(item.indexOf("title"));
String title = getTitle(substringWithTitle);}
Community
  • 1
  • 1
S.B.Wrede
  • 123
  • 1
  • 2
  • 10
0
if(textLine.startwith("title"){
    s = s.substring(textLine.indexOf("\"") + 1);
    s = s.substring(0, s.indexOf("\""));f
    System.out.println(s);
}
SedJ601
  • 12,173
  • 3
  • 41
  • 59