preload

Inserting breaks into text line

Posted by Albert Gareev on Aug 19, 2010 | 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 Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.