No strip the strings

hi,

i have a string in db... like this,

test

t

t

ttest

st

asdf

sf

dsfsd

how to display it as it is in jsp page?

ofcourse it displays for me now test

t t ttest st asdf sf dsfsd

[282 byte] By [loguKKa] at [2007-11-27 11:09:29]
# 1

String partTextHTML = partText.replace( System.getProperty( "line.separator"), "<br />");

this will make the "enters" a <br /> so html knows it's an enter sign

In PHP you have a handy function nl2br() for this, but afaik Java does not

radicjesa at 2007-7-29 13:35:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

[nobr]Then just write your own utility method ;)

The line.separator property is not fully safe, it *can* differ per system. The following method is safe:

public static String nl2br(String input) {

return input.replaceAll("(\r\n|\n\r|\r|\n)", "<br />");

}

[/nobr]

BalusCa at 2007-7-29 13:35:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> The line.separator property is not fully safe, it

> *can* differ per system.

I always thought that that method was used because it differs per system?

How can it not be fully safe, it takes the system's line separator right? So when you switch to a different system it will automatically use the new one or?

radicjesa at 2007-7-29 13:35:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

If you store the linebreaks as CRLF in the database and then move it to a system which uses LFCR als linebreaks, then you're lost.

BalusCa at 2007-7-29 13:35:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...