Inserting breaks into text line

Categories: Source codeText Data

Parent page: Service Functions – String (QTP, VBScript)

Description

Based on the maximum allowed length of the string (strMsgText) insert space characters.

Implementation

Public Function BreakTextLine(ByVal strMsgText, ByVal intMaxLen)
 Dim intLoc, intMaxLen, strResult
 If Len(strMsgText) < intMaxLen Then
 BreakTextLine = strMsgText
 Exit Function
 End If
 strResult = ""
 While Len(strMsgText) > 0
 intLoc = InStr(1,strMsgText," ")
 If intLoc = 0 Then
 strResult = strResult & Left(strMsgText, intMaxLen) & " "
 strMsgText = Mid(strMsgText, intMaxLen+1)
 Else
 If intLoc <= intMaxLen Then
 strResult = strResult & Left(strMsgText, intLoc)
 strMsgText = Mid(strMsgText, intLoc+1)
 Else
 strResult = strResult & Left(strMsgText, intMaxLen) & " "
 strMsgText = Mid(strMsgText, intMaxLen+1)
 End If
 End If
 Wend
 BreakTextLine = strResult
End Function

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by the author is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.