Text break by delimiter

2

I have the following text:

Texto|Texto|Texto|

I want to display it in a TextView, but every "|" (pipe) it will break the line.

In this way:

String texto = this.textoQuebrado;
String[] array = texto.split("|");
conteudo.setText(Arrays.toString(array));

It looks like this:

|T|e|x|t|o|||T|e|x|t|o|||T|e|x|t|o||

    
asked by anonymous 20.10.2017 / 13:26

1 answer

3

Try using replace :

String texto = "Texto|Texto|Texto|";
System.out.println(texto.replace("|", "\n"));

Output:

Texto
Texto
Texto

See: link

Remembering that the TextView component accepts line breaks using \n normally.

    
20.10.2017 / 13:52