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

Textarea problems

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
US
I am creating a text editor so a client can enter text and post to a database, to use later in emails. Problem is, when he cuts and pastes his text, the wrapping is off. I have the following but it's not doing any good:
body = Replace(body, vbCrLf, &quot;<BR>&quot;)
If there is no physical hard return, it's not including the <BR> and the line goes on forever. Any way I can force a <BR>? Like after a character count include a <BR>? Any thoughts would be appreciated.
 
Try This:

REPLACE(REPLACE(yourString,CHAR(10),''),CHAR(13),'<br>')
 
OOPS!!!

REPLACE(REPLACE(yourString,CHAR(10),'<br>'),CHAR(13),'<br>')
 
Thanks very much for your reply. It is still not wrapping. I'll keep trying. Thanks again.
 
Well, for the challenge of it I wrote some code, basically it takes the first section of 50 characters, finds the last space, replaces the spaces, takes the next 50 characters starting at that last space, finds the last space, replaces, etc...
You should be able to alter it to fit your needs:
Code:
Function linebreaks(myString)
	dim ln, lastSpc
	ln = len(myString)
	lastSpc = 1

	Do While ln - lastSpc > 50
		lastSpc = lastSpc + lStr(mid(myString,lastSpc,50),&quot; &quot;)
		If lastSpc > 0 Then
			myString = left(myString,lastSpc-1) & &quot;_<br>&quot; & right(myString,ln - lastSpc)
		End If
		lastSpc = lastSpc + 4 'to make up for <br> tag characters
	Loop
	linebreaks = myString
End Function

Function lStr(str1,str2)
	'Finds last occurrence of str2 in str 1
	Dim wrk, fin
	fin = 0
	wrk = InStr(1,str1,str2,1)
	Do Until wrk = 0
		fin = wrk
		wrk = InStr(fin+1,str1,str2,1)
	Loop
	lStr = fin
End Function

Thanks for a good challenge and I hope I didn't do this the hard way and you find it helpful :)

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Thank you very much Tarwin. I will try your method. One question, though. How do I implement it? Thanks again!
 
Thanks again, Tarwin. I really don't know how to use the above. I made mystring = request.form(&quot;body&quot;) but from there I don't know what to do. I get type mismatch errors on the variable linebreaks and lStr. Thanks again.
 
Just Response.Write linebreaks(request.form(&quot;body&quot;)) and it should do the rest for you.

One addition, the lStr function is absolutely necessary, due to another post recently I heard about the InStrRev function which does the same thing as the function lStr above that I created.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top