Forums Register Login

\n in a string for output

+Pie Number of slices to send: Send
I'm building a string in a for loop and would like to have a new line separator in my string. At this point I have the following:
strT50 += paramKey+" - "+strPercent+"; \n";
I also tried <br> instead of \n.
In both cases, the output in a webpage doesn't show as a new line.
Can someone please tell me how to format a string in jsp so that it containes new lines when needed?
Thanks in advance.
+Pie Number of slices to send: Send
Remember, you're emitting HTML so the <br> should have worked for you -- the \n will obviously not.

Look at the HTML that is sent to the browser to determine why it's not laying out as you wish.
+Pie Number of slices to send: Send
When I use <br> in
strT50 += paramKey+" - "+strPercent+"; <br>";

my webpage enterptites it literally and shows "<br>" for some reason...
+Pie Number of slices to send: Send
If you are emitting it with <c:out>, the output will be HTML-encoded. Look up the attiributes to <c:out> to see how to make it stop doing that.
[ August 01, 2006: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
How are you outputting this string "strT50"?
If you are doing it with a <c:out> tag, it will automatically escape the < and > characters into < and >

You could make it <c:out value="${strT50}" escapeXml="false"/>

An alternative while still using the "\n" character is to surround the string you are printing out with <pre> tags in the html.
The <pre> tag tells HTML the text is pre-formatted, and shouldn't be modified according to the normal rules.

<pre><c:out value="${strT50}"/></pre>

Hope this helps,
evnafets
+Pie Number of slices to send: Send
Very nice! escapeXml="false" worked well!
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1206 times.
Similar Threads
RE: Replace "\n" with "\\n"???
New line problem
New line in quoted string
How to read a '\n; new line character from Sybase DB ?
Writing a new line character
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:13:17.