WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Strings

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Wrap Text to Fixed Size

 Keywords: Fixed Width Wrap string text full words 

; StrWrap adapted from:
; This version works for text with or without spaces
; Les Ferch, May 2009

#DefineFunction StrWrap(Text,Wrap)
Offset = 1
While Offset + Wrap<=StrCharCount(Text)
   If StrCharCount(Text)<Offset + Wrap
      Offset = Offset + StrCharCount(Text)
   Else
      TmpStr = StrSub(Text,Offset,Wrap)
      FindLF = StrIndex(TmpStr,@LF,Wrap,@BACKSCAN)
      FindSpace = StrIndex(TmpStr," ",0,@BACKSCAN)
      If FindLF>0
         Offset = Offset + FindLF
      Else
         If FindSpace==0 Then FindSpace = Wrap
         TmpStr1 = StrSub(Text,1,Offset + FindSpace - 1)
         TmpStr2 = StrSub(Text,StrCharCount(TmpStr1) + 1,StrCharCount(Text) + 1 - StrCharCount(TmpStr1))
         TmpStr2 = StrTrim(TmpStr2)
         Text = StrCat(TmpStr1,@LF,TmpStr2)
         Drop(TmpStr1,TmpStr2)
         Offset = Offset + FindSpace + 2
      EndIf
   EndIf
EndWhile
Return Text
#EndFunction

; Test
Text = "The bizarre appearance of this egg-laying, venomous, duck-billed, beaver-tailed, otter-footed mammal baffled European naturalists when they first encountered it, with some considering it an elaborate fraud. It is one of the few venomous mammals; the male Platypus has a spur on the hind foot that delivers a venom capable of causing severe pain to humans."
BoxOpen("Test",StrWrap(Text,88))
TimeDelay(8)

Article ID:   W17270
File Created: 2009:05:28:14:38:48
Last Updated: 2009:05:28:14:38:48