Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Format on ASP

Status
Not open for further replies.

adolsun

Programmer
Jan 13, 2004
52
GB

I've created my database on MS Access and linke it to the web using ASP. I can display data from db. The problem I have now is when I display a data from db on ASP page I get the text as one block with no spaces or paragraphs format. Can anybody give me a hand of how to display my text as I entered.

Note: I stored text on field with memo type.

Thanks
 
Have you formatted the text in the db as any normal text, i.e. with hard returns?

If so, you could do a
Code:
response.write replace(rs("yourfield"),vbcrlf,"<br>")

Or wrap your output command in "<PRE>" Tags:
Code:
response.write "<pre>" & rs("yourfield") & "</pre>"

Hope this helps.

Cheers,
Andy

[blue]An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi[/blue]
 
This will replace all the carriage returns/line breaks with valid HTML line breaks.
Code:
strText = Replace(objRS("MemoField"), vbcrlf, "<br />")

Tony
[blue]________________________________________[/blue]
 
;-)
You'll beat me to it the next hundred times again, Tony...
[glasses]

[blue]An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi[/blue]
 
Your sounds seem higher than my level. The property field of memo field (called: body)is empty.

Here’s my code; please can you tell me where exactly I should write what you said:
Code:
<!--#include file=connection.inc -->
<%
'Select table and get data
selectnewsSQL="select * from TABLE1"
set rsnews=ADO.execute(selectnewsSQL)
%>
<P>
<%=rsnews("body")%>
</p><p>
<%=rsnews("body")%>
</p>
[\code]
Thanks in advance.
 
Tony; Brilliant it’s working now .. I appreciate your help. Thanks a lot and thank you MakeItSo for your attention and try.
 
Oh, also you might want to add the same thing except for tabs instead of line breaks. You could wrap one call to Replace() with another...

Code:
<%=Replace(Replace(rsnews("body"), vbcrlf, "<br />"), vbTab, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")%>

If that makes too many spaces you remove some of the &nbsp;
 
Yah ! Thank you for your co-operative. Shell we go more advance on formatting text on ASP, well ..

Suppose I entered my text from front end and the text contains sub-titles, which must be in different format (I used CSS). How can I format this sub-title without writing manually this line?
Code:
<SPAN class=subTitle>Anything</SPAN>
Is that possible? Sorry I'm new on ASP !
 
I use a forum style markup code in the database

so [st]This is a subtitle[/st] would be replaced with

<span class="subTitle">This is a subtitle</span> on rendering out to the user agent.

So the markup and replacements are in a 2d array
example using part of the colour replace section
Code:
ReplaceCode(10,0) = "[color=red]"
ReplaceCode(10,1) = "<span style=" & chr(34) & "color:#FF0000;" & chr(34) & ">"
ReplaceCode(11,0) = "[color=blue]"
ReplaceCode(11,1) = "<span style=" & chr(34) & "color:#0000FF;" & chr(34) & ">"
ReplaceCode(27,0) = "[/color]"
ReplaceCode(27,1) = "</span>"
obviously this is just a small sample.

then
Code:
function ReplaceMarkUp(strItem)
dim i
for i = 0 to ubound(ReplaceCode)
	strItem = replace(strItem, ReplaceCode(i,0), ReplaceCode(i,1))
next
strItem = replace(strItem,">",">" & Chr(13))
strItem = replace(strItem,"<", Chr(13) & "<")

ReplaceMarkUp = strItem
end function




Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top