Text break by delimiter

Asked

Viewed 296 times

0

I have the following text::

Texto|Texto|Texto|

I want to display it in a Textview, but every "|" (pipe) it breaks the line.

In this way:

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

Comes out like this:

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

  • 2

    texto.replace("|", "\n");

  • @Articuno has no way without using line break ?

  • In the question you say mas a cada "|" (pipe) ele quebrar a linha..

  • It is true, I lost myself on account of sometimes the n not being recognized, but it is something else ! I traveled ! Thanks !

1 answer

2


Try with replace:

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

Exit:

Texto
Texto
Texto

Behold: https://ideone.com/hp9Jj7

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.