I have researched this for days now and everything I have tried has failed.
I am using classic ASP and MySql database.
I am not sure where else to turn. I have read similar questions here, but the solutions did not work for me.
Any help will be most appreciated.
I tried using
<p STYLE="word-wrap: break-word;width:200"><%=V12%></p>
and this gave me the correct wrapping, but didn’t keep the paragraph spacing.
I tried using <pre>
and this gave me the spacing, but gave me no word wrap.
I tried V12 = Replace(INFO1("STORY_"),vbCrLf,"<BR>")
and this did nothing.
2
Answers
To preserve line breaks from a database field I used to use
However for the last few years I’ve been using the CSS style
white-space: pre-line
. It’s client side code (obviously) so you can use it with whatever back end you have.You’re replacing
VBCrLf
when you need to be replacingVBLf
(or ideally both).Depending on the OS/software used to create a string, a line break can either be represented as a line feed (
VBLf
orChr(10)
) or a carriage return and a line feed (VBCrLf
orChr(13)
). You can have a carriage return on it’s own, but this wouldn’t initiate a new line I don’t think.This answer/thread explains it well:
https://stackoverflow.com/a/12747850/4901783
So when replacing line breaks, you need to check for both
VBLf
andVBCrLf
.As for paragraph formatting, replacing a line break with
</p><p>
will close an existing paragraph and open a new one. Just as long as you also wrap the output inp
markers too.You could do all of this in a function, such as: