You can print, say, the left 200 characters or so of a block of text as follows:
<% bigtext = "Hello, this is a big paragraph of text, used" & _ " solely for demonstration purposes. The code" & _ " will return the first 200 characters or so" & _ " to simulate some kind of ""excerpt"" where" & _ " you would later click for more info..." excerpt = left(bigtext, instrRev(LEFT(bigtext, 200), " ")-1) & "..." response.write excerpt %> |
If you want to add a space before the "...", either take out the -1, or add a leading space, e.g. " ..."
Having said that, if this information is coming from a database, you might want to adjust your query to be more efficient; for example, only returning the first 200 or so characters across the wire (this is especially true for TEXT columns, which often contain far more data than you would ever need to show in an excerpt... so why return it?).
SQL Server doesn't support an InstrRev-like function, so the query is a little more complicated than it might otherwise be:
SELECT excerpt = SUBSTRING ( column, 1, 200-CHARINDEX ( ' ', REVERSE ( SUBSTRING ( column, 1, 200 ) ) ) )+'...' FROM table |
In Access, the query is a LOT more like the VBScript version, since Access supports VBA:
SELECT excerpt = LEFT ( column, INSTRREV ( LEFT ( column, 200 ), " " )-1 ) & "..." FROM table |
However, you might find that this query doesn't work from ADO (see
Article #2394). If this is the case, then just take the left 250 characters or so, and then apply the same logic in your ASP code as above. Please
let us know if you have problems implementing any of these suggestions.