Duvida com quebra de linha

2 respostas
F

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.

valeu

Fábio

2 Respostas

mlopes

Ola,

Talvez isso te ajude:

/**
	 * 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.
	 */
	public static String formatLines(String target, int maxLength, Locale currentLocale)
	{
		BreakIterator lineBreaker = BreakIterator.getLineInstance(currentLocale);

		lineBreaker.setText(target);

		StringBuffer lines = new StringBuffer();
		int start = lineBreaker.first();
		int end = lineBreaker.next();
		int lineLength = 0;

		while (end != BreakIterator.DONE) {
			String word = target.substring(start, end);

			lineLength = lineLength + word.length();
			if (lineLength >= maxLength) {
				lines.append("
");
				lineLength = word.length();
			}
			lines.append(word);
			start = end;
			end = lineBreaker.next();
		}

		return lines.toString();
	}

[]'s

mlopes

Oops,

Tem um n que foi interpretado como quebra de linha.
Lembre-se de colocá-lo.

[]'s

Criado 11 de fevereiro de 2003
Ultima resposta 11 de fev. de 2003
Respostas 2
Participantes 2