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
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
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
[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]
> 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?
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.