<% '//////////////////////////////////////////////////////////////////////////////////////// '/// Public Function WordWrap(strTextToBeWrapped, intMaxLineLength) returns string '/// '/// purpose: Here's the function that does the work. It takes a string '/// to word wrap and a maximum line length and returns the '/// string wrapped appropriately. '/// '/// History: '/// 01.10.01 HEPFERM Function taken from a wordwrap example found '/// at www.asp101.com that was provided strictly for the '/// purpose of illustration. Please direct all inquiries to '/// webmaster@asp101.com '/// 01.12.01 HEPFERM Added a "
" to the strWrappedText inside. see comments. '/////////////////////////////////////////////////////////////////////////////////////// Public Function WordWrap(strTextToBeWrapped, intMaxLineLength) Dim strWrappedText ' Result storage Dim intLengthOfInput ' Length of original Dim intCurrentPosition ' Where we're at now Dim intCurrentLineStart ' Where the current line starts Dim intPositionOfLastSpace ' Last space we saw ' Get this once so we don't have to keep checking intLengthOfInput = Len(strTextToBeWrapped) ' Start both of these at the beginning intCurrentPosition = 1 intCurrentLineStart = 1 ' Loop through until we get to the end Do While intCurrentPosition < intLengthOfInput ' If the current position is a space, make a note of ' it's location for later use. If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then intPositionOfLastSpace = intCurrentPosition End If ' If we're at what should be the end of a line, we go back ' to the last space we saw and cut the line there. If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then ' Some debugging lines if something's not lining up. 'Response.Write intCurrentLineStart & "
" 'Response.Write intPositionOfLastSpace & "
" 'Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart, _ ' intPositionOfLastSpace - intCurrentLineStart + 1)) & "
" ' Append this latest line to our result strWrappedText = strWrappedText _ & Trim(Mid(strTextToBeWrapped, _ intcurrentLineStart, _ intPositionOfLastSpace - intCurrentLineStart + 1)) _ & "
" & vbCrLf ' added the "
", becuase it wasn't wrapping ' Reset the next line's starting point to the point we ' used for the last one's end + 1. intCurrentLineStart = intPositionOfLastSpace + 1 ' Remove any leading spaces that might mess up our ' character count. If you want to just pull of one, ' switch this to a simple If conditional instead of ' looping. Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " " intCurrentLineStart = intCurrentLineStart + 1 Loop End If ' Increment our location indicator. intCurrentPosition = intCurrentPosition + 1 Loop ' Since the loop ends before we add the remaining text, ' add remaining text as the last line. strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped, _ intcurrentLineStart)) & vbCrLf ' Return our result to the calling line. WordWrap = strWrappedText End Function %>