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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cropping first paragraph

Status
Not open for further replies.

amiw

Programmer
Apr 1, 2003
113
GB
How could we crop the first paragraph of our news that comes from a database.
Would we look for the first a full stop with a couple of spaces after it? or would there be other considerations?
 
You could get the first 100 characters and append '...' to the end, or to make it neater get the first space after the 100th char and do it then so that you get a whole word. That way you get a decent amount of control over the amount of text which is displayed.
 
Shatch, sorry I know how to do that, its not what I am looking for.
 
If you want the first paragraph you could break at the first vbcrlf (enter key) of the text rather than looking for full stops...
 
I ran a test with a form and the code below, when I entered text into the form and clicked the enter button for a line break and then entered some more text, I noticed that only the first piece of text was entered into the database

tarea=Replace(Request.form("textarea")
sSQL="INSERT INTO table1(mbody) Values('" & tarea & "')"
response.write sSQL
Set Connection = Server.CreateObject("ADODB.Connection")
sConnString="Driver={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("db1.mdb")
Connection.open sConnString
connection.execute sSQL

any ideas as to why there is no vbcrlf in the memo field and no text that followed the line break?
 
here is a small function found online that preserves the vbcrlf in the database

Code:
<%
Function FormatStr(String)
on Error resume next
String = Replace(String, CHR(13), "")
String = Replace(String, CHR(10) & CHR(10), "</P><P>")
String = Replace(String, CHR(10), "<BR>")
FormatStr = String
End Function
%>
Here is the formated string:<br>
<%=FormatStr(to_html(rs.Fields("Memo_Field")))%>

-DNG
 
thanks for that dotnetgnat,
but one of the problems is trying to insert the line break into the database and why any text after the line break isnt inserted.
any ideas?
 
with the above function you can trap the vbcrlf(the new line character) and store it in the database and once you do i am sure you can insert the text that follows this new line character without any problems...did you try using the function and see what is actually getting inserted into the database...

just try this code

Code:
[red]tarea=Replace(Request.form("textarea"),vbCRLF," ")[/red]
[blue]'tarea=Replace(Request.form("textarea"),vbCRLF,"<br/>")[/blue]
sSQL="INSERT INTO table1(mbody) Values('" & tarea &  "')"
response.write sSQL
Set Connection = Server.CreateObject("ADODB.Connection")
sConnString="Driver={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("db1.mdb")
Connection.open sConnString
connection.execute sSQL

try only one Replace statement and check how the data gets inserted...

-DNG
 
I used the code

tarea=Replace(Request.form("textarea"),vbCRLF,"<br />")
sSQL="INSERT INTO table1(mbody) Values('" & tarea & "')"
response.write sSQL
Set Connection = Server.CreateObject("ADODB.Connection")
sConnString="Driver={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("db1.mdb")
Connection.open sConnString
connection.execute sSQL

and it didn't work, only inserts the first piece of text.

second in your code

<%
Function FormatStr(String)
on Error resume next
String = Replace(String, CHR(13), "")
String = Replace(String, CHR(10) & CHR(10), "</P><P>")
String = Replace(String, CHR(10), "<BR>")
FormatStr = String
End Function
%>
Here is the formated string:<br>
<%=FormatStr(to_html(rs.Fields("Memo_Field")))%>

where's the to_html function, or is that a built in function?

thanks.

 
just remove that function and use:

<%=FormatStr(rs.Fields("Memo_Field"))%>

-DNG
 
ok thanks for the link

what about the inserting issue and the string being truncated somewhat, any ideas why this might be happening?
 
When using something like this:
="INSERT INTO table1(mbody) Values('" & tarea & "')"

You probably want to check for "SQL Injection" attacks...

Suppose the text area contained this:
blah') Go DROP TABLE table1 Go SELECT * FROM fake WHERE field = 'whatever

Then, when you go to execute the code, you've got:
INSERT INTO table1(mbody) Values('blah')
Go
DROP TABLE table1
Go
SELECT * FROM fake WHERE field = 'whatever')

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top