Here's a VB.Net function for use in an asp.NET script.
You can translate it into any other server side script language as you see
fit, or even into JavaScript for browser.
To display in the browser you need to add
replace(vbCrLf, "<br />")
somewhere after the function call
Function formatTextBox(byVal txt as string, byVal linelength as Integer) as
String
'txt is the string (from the textbox) to be formatted
'linelength is the length of the required line in characters
Dim finalstr as String = ""
Dim tmp as String = ""
Dim jj as Integer = 0
'Start a loop to parse through the string
Do While Len(txt) > linelength
tmp = Left(txt, linelength) ' assign left end to tmp
jj = InStrRev(tmp, " ") ' look for a space character to break the line
at
If jj>0 Then
'and add up to that space to the result, plus a line feed
finalstr &= left(tmp, jj-1) & vbCrLf
' remove that text from the original
txt = Mid(txt, jj+1)
Else
'If no space, just cut the string
finalstr &= tmp & vbCrLf
txt = Mid(txt, linelength + 1)
End If
Loop
'Add whatever's left (less than linelength characters)
finalstr &= txt
Return finalstr
End Function
--
Ron Symonds
Microsoft MVP (Expression Web)
http://www.rxs-enterprises.org/fp
Reply only to group - emails will be deleted unread.