I need to get make a break inside a string that will output in HTML;
String str = "Hello <br /> There";
would output:
Hello
There
I need to get make a break inside a string that will output in HTML;
String str = "Hello <br /> There";
would output:
Hello
There
Share
Improve this question
edited Apr 20, 2019 at 19:49
Suragch
512k338 gold badges1.4k silver badges1.4k bronze badges
asked Sep 3, 2014 at 18:42
LucaSpeedStackLucaSpeedStack
5112 gold badges7 silver badges22 bronze badges
6
- Hi, can you be more specific? What have you tried and what didn't work? – Seth Ladd Commented Sep 3, 2014 at 19:48
- @SethLadd I have tried everything. All I want is to make a String with a break, then put it into an HTML element, such as a div, and make the text appear on more than 1 line. – LucaSpeedStack Commented Sep 3, 2014 at 19:52
- You haven't shown what you tried and what the error was. That will really help us answer your question. – Seth Ladd Commented Sep 3, 2014 at 19:53
- @SethLadd With the above example in my question: no errors e up but only <br /> appears. – LucaSpeedStack Commented Sep 3, 2014 at 19:54
- @SethLadd I don't know what else to try.. – LucaSpeedStack Commented Sep 3, 2014 at 19:56
1 Answer
Reset to default 12Try
String str = "Hello\nThere";
instead.
Might need to apply white-space: pre
or white-space: pre-wrap
to the style of the element where you're displaying the text, though.