Tenho um texto de uma linha em meu banco de dados com tamanho de 400 caracteres, como eu posso quebra este texto em 4 linhas na impressao, estou usando o FileWriter para imprimir e uso o
para quebrar linha, mas não consegui pensar em um algoritmo. Nem sempre os 400 caracters estão preenchidos.
/** * format the string passed as lines of the maxLength length. * @autor [email removido] * @param target the string to be formatted. * @param maxLength The number of columns each line should have. * @param currentLocale The locale to be used when formatting * @return the formatted string with line breaks. */publicstaticStringformatLines(Stringtarget,intmaxLength,LocalecurrentLocale){BreakIteratorlineBreaker=BreakIterator.getLineInstance(currentLocale);lineBreaker.setText(target);StringBufferlines=newStringBuffer();intstart=lineBreaker.first();intend=lineBreaker.next();intlineLength=0;while(end!=BreakIterator.DONE){Stringword=target.substring(start,end);lineLength=lineLength+word.length();if(lineLength>=maxLength){lines.append("");lineLength=word.length();}lines.append(word);start=end;end=lineBreaker.next();}returnlines.toString();}
[]'s
mlopes
Oops,
Tem um n que foi interpretado como quebra de linha.
Lembre-se de colocá-lo.