Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
s = Split(str, " ")
WrapText = s(0)
For i = 1 To UBound(s)
If Len(WrapText) Mod 80 > Len(WrapText & " " & s(i)) Mod 80 Then
WrapText = WrapText & vbCrLf & s(i)
Else
WrapText = WrapText & " " & s(i)
End If
Next
Option Explicit
Dim strString
strString = String(80, "a") & String (80, "b") & String(80, "c")
WScript.Echo "BEFORE: " & VbCrLf & strString
strString = InsertReturns(strString, 80)
WScript.Echo "AFTER:" & VbCrLf & strString
Function InsertReturns(strTxt, nCount)
Dim nInsert
nInsert = nCount
Do While nInsert < Len(strTxt)
strTxt = Left(strTxt, nInsert) & VbCrLf & Mid(strTxt, nInsert + 1)
nInsert = nInsert + nCount + 2
Loop
InsertReturns = strTxt
End Function
Function WrapText(str As String)
s = Split(str, " ")
WrapText = s(0)
For i = 1 To UBound(s)
If Len(WrapText) Mod 80 > Len(WrapText & " " & s(i)) Mod 80 Then
WrapText = WrapText & vbCrLf & s(i)
Else
WrapText = WrapText & " " & s(i)
End If
Next
End Function
Option Explicit
Dim strString
strString = String(80, "a") & String (80, "b") & String(80, "c")
WScript.Echo "BEFORE: " & VbCrLf & strString
strString = InsertReturns(strString, 80)
WScript.Echo "AFTER:" & VbCrLf & strString
strString = "This is a very long line. I will get a lot of text with no line breaks" _
& " It would seem that neither solution is perfect. It is true that mine will put" _
& " the return at the 80th char regardless of the word break. Your solution will" _
& " not put a return at all if the string has no spaces. My solution would put the" _
& " return in place of a space at the last space in the string before the 80th character."
WScript.Echo "BEFORE: " & VbCrLf & strString
strString = InsertReturns(strString, 80)
WScript.Echo "AFTER:" & VbCrLf & strString
Function InsertReturns(strTxt, nCount)
Dim nInsert
Dim nBreak
nInsert = nCount
Do While nInsert < Len(strTxt)
nBreak = InStrRev(strTxt, " ", nInsert)
If nInsert - nBreak > nCount Then
strTxt = Left(strTxt, nInsert) & VbCrLf & Mid(strTxt, nInsert + 1)
Else
nInsert = nBreak
strTxt = Left(strTxt, nInsert) & VbCrLf & Mid(strTxt, nInsert + 1)
End If
nInsert = nInsert + nCount + 2
Loop
InsertReturns = strTxt
End Function