-1
Someone has an idea to help me extract the lines below and that always present themselves in this pattern?
Palavra1 (é sempre igual)
Linha a ser extraida, de tamanho variavel
Linha a ser extraida, de tamanho variavel
Linha a ser extraida, de tamanho variavel
Palavra2 (é sempre igual)
bla bla bla
bla bla bla
Palavra1 (é sempre igual)
Linha a ser extraida, de tamanho variavel
Linha a ser extraida, de tamanho variavel
Linha a ser extraida, de tamanho variavel
Palavra2 (é sempre igual)
The 3 lines are parts of the same information that I should store in a single variable and display to the user, but that, at the time of file conversion, were thrown in 2, 3 or 4 lines.
Follow the code I imagined so far:
StringBuilder sb = new StringBuilder();
if(linha.startsWith("palavra1")){
linha = arquivoEntrada.readLine() + 1; //pula a linha
if(!linha.startsWith("palavra2")){ //minha condição de parada
sb.append(linha + " "); //StringBuffer pra ir armazenando as linhas lidas
//como fazer o sistema pular a linha agora??????
} else {
}
variavelQualquer = sb.toString();
}
With this code, I can only get the first line. I tried with while
instead of the second if
, but it didn’t work.
Any help would be welcome.
Can you post any more snippets of code? I think it would help to understand what you’re doing and propose something closer to what you need.
– Maniero
Briefly, I had a PDF file that was converted to txt. My job is to manipulate via substring certain information from this generated TXT and finally create another final TXT file displaying only the manipulated information. In this case, these 3 or more lines that I illustrated should be in a single line (ie, they are the information I need), but the PDF converter p/ TXT ended up breaking and playing in several lines. I need now, then, to reunite them again and play in the final TXT as a single line. I hope it has become clearer now.
– StatelessDev
The absence of at least one cycle makes me see that you should only read the first line.
– Cold
@Cold, I tried to use the while, but it burst of memory. Anyway, the if should work if my logic is correct.
– StatelessDev
@bigown My logic was to try to work with the regularity that allows me to identify the block of lines that I need, and that regularity is the existence of the same word before those lines and another word after those lines. I mean, the lines I need are always on a block bounded by two words that are always the same.
– StatelessDev