Problème ligne.indexof() index
Bonjours a tous ,
Donc voila mon pb je dois récupérer des données d'un txt.
J'utilise donc une condition if pour trouve le text avant celui que je dois trouver puis je fais un substring pour enregistrer le mot a recuperer.
Les position du substring utilise les index.of() du caractere precedent et suivant du mot a recupere
Seul problem mes ligne ne sont pas tjrs de la meme longeure et j ai donc defois des indexof du caractere suivant qui est egal a -1
Jusqua present j ai essaye de rajoute des blanc pour avoir le meme nombre de ligne partout mais je n arrive pas .
Donc je voudrai savoir comment faire pour que le indexof du suivant soit juiste ou comment identifier le caractere suivant pour recupere mon mot
Merci de votre aide voici le code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| if(stri.equals(wunch)) {
cell.setCellValue("Modul");
row.createCell(1).setCellValue("Wunsche");
//Read Text Document
InputStream inpStre=new FileInputStream(str);
InputStreamReader inpStreRead=new InputStreamReader(inpStre);
BufferedReader bufRead = new BufferedReader(inpStreRead);
while((ligne=bufRead.readLine())!=null){
boolean found = false;
if(ligne.indexOf(srtfound) !=- 1){
//Steck found
mdl = ligne.substring(1, 9) ;
System.out.println(mdl);
}
else if (ligne.indexOf(when) !=-1 ){
//Modul found
int i = ligne.indexOf(when);
int j;
int l = ligne.length();
System.out.println(l);
j = ligne.indexOf(quote);
cpbook = ligne.substring(i+6, j);
found = true;
System.out.println(" debut "+i);
System.out.println(" longueur fin "+j);
}
if (found == true){
//Create the Excel Line
rowNb ++;
HSSFRow rw = sheet.createRow(rowNb);
HSSFCell cel0 = rw.createCell(0);
cel0.setCellValue(mdl);
HSSFCell cel1 = rw.createCell(1);
cel1.setCellValue(cpbook);
} |