Ich habe eine Datei, die etwas Text und am Ende eine Nummer enthält. Die Datei ist wie folgt:Lesen Sie eine Datei und gruppieren Sie ihren Text
to Polyxena. Achilles appears in the in the novel The Firebrand by Marion
the firebrand 14852520
fantasy novelist David Gemmell omic book hero Captain Marvel is endowed with the courage of Achilles, as well
captain marvel 403585
the city its central theme and
corfu 45462
Was ich will ist, den gesamten Text bis zur Nummer zu gruppieren. Beispiel:
" to Polyxena. Achilles appears in the in the novel The Firebrand by Marion the firebrand 14852520"
" fantasy novelist David Gemmell omic book hero Captain Marvel is endowed with the courage of Achilles, as well captain marvel 403585"
Ich bemerkte, dass jede Textgruppe mit Leerzeichen beginnt. Allerdings habe ich Schwierigkeiten, sie zu gruppieren. Ich codiert dies:
String line;
String s = " ";
char whiteSpace = s.charAt(0);
ArrayList<String> lines = new ArrayList<>();
BufferedReader in = new BufferedReader(new FileReader(args[0]));
while((line = in.readLine()) != null)
{
if (whiteSpace == line.charAt(0)){ //start of sentence
lines.add(line);
}
}
in.close();
Eigentlich nur Sie die Linien mit einem weißen Raum auf der Vorderseite auf die „Linien“ Arraylist direkt hinzufügen ?. Also zB. _the firebrand 14852520_ sollte nicht im Array richtig? Vielleicht versuche es mit einem Index. Daher werden alle Zeilen zwischen zwei Leerzeichen einem Index hinzugefügt. Erhöhen Sie den Index, wenn eine Zeile mit einem Leerzeichen beginnt. – theoretisch