Hi guys,
I've got a HTML form where people can insert some text into a mutiilne text box and then inserts this into a database.
Problem is every time the text is changed it inserts a line break at the end until eventually it has loads of line breaks and breaks the code.
Does anyone know how I can search and replace multiple line breaks and replace it with just one?
I presume this will have to be done in a loop until there are no more than one line break in a row?
Any ideas?
Thanks,
Suzy 
Hi Suzy,
I assume that you mean you have <textarea> element on the form?
Is there any server side processing going on before you insert into the db (converting line breaks to <br>) that could be adding in the extra line breaks?
I assume that there is some sort vbcrlf replace happening somewhere?
'' untested ASP myText=Replace(myText, "", "") myText=Replace(myText, vbcrlf & vbcrlf , vbcrlf )
If I were doing it in PHP, I'd replace all tags with line breaks ("\n"), do a trim(), and then replace the line breaks with s. Presumably there's an ASP equivalent of trim().
Yes it is a but there is no converting anything before it goes in the database or any other replaces going on.
Stickman - there is trim in ASP so that might be the best way to go - I'll give it a try 
Well for anyone wanting to do it in ASP I did it a rather long winded way by doing the following when the results are outputted:
' Remove all trailing line returns after text pDesserts = rsMenus(Trim("Desserts")) pDesserts=Replace(pDesserts, " ", " ") pDesserts=Replace(pDesserts, vbcrlf, " ") pDesserts=(Trim(pDesserts)) pDesserts=Replace(pDesserts, " ", vbcrlf) pDesserts=Replace(pDesserts, " ", " ")
But then like a muppet I realised I need to do it before it goes in the database!
The issue here Suzy, is why the extra line breaks are appended in the first instance.
Want to post the code that takes the form input and inserts it to the db? Is there some data sanitising that might be causing the problem?
All I've got is this:
rsUpdate.Fields("Desserts") = (RTrim(Request.Form("Desserts")))
There is no data sanitising as it just an application on a computer and not web based.
Oh well the code sorted it which is the main thing. It's something I developed nearly three years ago and I'm just trying to quickly fix a few bugs for them so the main thing is they will be happy.
Thanks for all your help guys 
When it comes to fixing old code, as with so many things, quick'n'dirty is the way to go. :thumbsup: