|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Oct 2011
Messaggi: 45
|
Problemi con la ricerca nel testo
Salve, il metodo che devo sviluppare deve cercare una determinata frase in un testo, usando lo StringTokenizer ho sviluppato il metodo:
Codice:
//il metodo verifica se la frase è presente nel testo
public boolean cercaFrase(String testo,String frase){
StringTokenizer parolaTesto=new StringTokenizer(testo);
StringTokenizer parolaFrase=new StringTokenizer(frase);
boolean stato=false;
String pt=parolaTesto.nextToken();
String pf=parolaFrase.nextToken();
String inizio=pf;
while(!stato||!parolaTesto.hasMoreTokens()){
if(pt==pf){
pt=parolaTesto.nextToken();
pf=parolaFrase.nextToken();
if(!parolaFrase.hasMoreTokens())
stato=true;
}
pt=parolaTesto.nextToken();
//mi serve un codice che mi porti parolaFrase al token iniziale
}
return stato;
}
__________________
Teo
|
|
|
|
|
|
#2 |
|
Member
Iscritto dal: Oct 2011
Messaggi: 45
|
Uso il main
Codice:
public static void main(String[] args) throws IOException {
CercaNelTesto cnt=new CercaNelTesto();
FileInputStream fis=new FileInputStream("Lettore a_rmato.pdf");
File f=new File("Lettore a_rmato.pdf");
EstrattoreTesto et=new EstrattoreTesto(fis,f.getName());
System.out.println("Il file si chiama: "+et.getNome());
String frase="il lettore";
System.out.println("Cerco la frase: "+frase);
int n=0;
boolean fine =true;
while(!fine){
n++;
System.out.println("Controllo la pagina: "+n);
if(cnt.cercaFrase(et.getTestoPagina(n), frase))
System.out.println("La frase è nella pagina: "+n);
else
System.out.println("La frase non è nella pagina: "+n);
if(n==et.getNumeroPg())
fine=false;
}
}
Codice:
Il file si chiama: Lettore a_rmato.pdf Cerco la frase: il lettore
__________________
Teo
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 03:24.



















