Formatting imported text with asp

hafa

Perch
Here's a bit of code to help with text imported from spreadsheets and access databases. It will create html code with all of the appropriate tags and encoding for xhtml strict compliance:

Example:

Let's say that you recieved a spreadsheet from a customer which had a text field that looked like this:

Code:
The apparent low bidder will be subject to a thorough and comprehensive review of its qualifications and Bid Documents to ensure that they are "responsive and responsible". 

The proposed contract is under and subject to Executive Order 11246, as amended by Executive Order 11375 dated October 13, 1977.

The script will render the following:

Code:
<p>The apparent low bidder will be subject to a thorough and comprehensive review of its qualifications and Bid Documents to ensure that they are &quot;responsive and responsible&quot;.</p><p>The proposed contract is under and subject to Executive Order 11246, as amended by Executive Order 11375 dated October 13, 1977.</p>

Apostrophies are also handled as well, and all other non-SGML compliant characters will be coded appropriately. So without further ado, here's the code:

Code:
<% 'This routine deals with data from Excel and Access...
Dim strtxt
'First make it html compliant
strtxt = Server.HTMLEncode(your_recordset.Fields.Item("your_text").Value)
'Then get rid of the apostrophes
strtxt =  Replace(strtxt, "'", "’")
'replace ch(10) with <p> and then change <p><p> to </p><p> so that we can have properly formatted text in the end...
strtxt = Replace(strtxt, Chr(10), "<p>")
strtxt = Replace((strtxt), "<p><p>", "</p><p>")
%>

Note that for long text fields imported to MSSQL from Excel, VbCrLf will not work, so I've used chr(10) here.

In the body of the document, just place the following:
Code:
<p><%Response.Write(strtxt)%></p>

Hope that this proves helpful...
 
Back
Top