Here's another function
PHP Code:
Public Function WordWrap(ByVal strTextToBeWrapped As String, ByVal intMaxLineLength As Integer) As String
Dim wrappedText As String
Dim lengthOfInput As Integer
Dim currentPosition As Integer
Dim currentLineStart As Integer
Dim positionOfLastSpace As Integer
lengthOfInput = Len(strTextToBeWrapped)
currentPosition = 1
currentLineStart = 1
Do While currentPosition < lengthOfInput
If Mid(strTextToBeWrapped, currentPosition, 1) = " " Then
positionOfLastSpace = currentPosition
End If
If currentPosition = currentLineStart + intMaxLineLength Then
wrappedText = wrappedText & Trim(Mid(strTextToBeWrapped, currentLineStart, positionOfLastSpace - currentLineStart + 1)) & vbCrLf
currentLineStart = positionOfLastSpace + 1
Do While Mid(strTextToBeWrapped, currentLineStart, 1) = " "
currentLineStart = currentLineStart + 1
Loop
End If
currentPosition = currentPosition + 1
Loop
wrappedText = wrappedText & Trim(Mid(strTextToBeWrapped, currentLineStart)) & vbCrLf
wrappedText = Replace(wrappedText, vbCrLf, "<br />" & vbCrLf)
Return wrappedText
End Function
Bookmarks