I have a string:
String text = "Nothing right in my brain. Nothing left in my brain"
I want to create a new string text2
that has 2-4 random new line from previous, such as:
"Nothing \n right \n in my brain. \n Nothing left in my brain"
or
"Nothing right in \n my brain. Nothing left in \n my brain"
How to create a new string with random new line between the words? I am thinking to get the index of whitespace, in order to insert new line after random whitespace. But I only keep getting the first whitespace index. Anyone know better approach to solve this? Thank you.
Aucun commentaire:
Enregistrer un commentaire