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

Winbatch Studio
plus

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

How to Wrap lines to a Specific Length

Keywords:   word wrap 

Question:

I want to select text and have it wrapped to a short line length. How can I accomplish this with WinBatch Studio ?

Answer:

Here is a WinBatch word wrapping script for use in WinBatch Studio's configurable context menu. Clicking the right mouse button anywhere within an open file will bring up the context menu. To make changes to the context menu, open the WSPOPUP.MNU file with File/Open, or access it from the context menu itself. Right click in the file, from the context menu dialog box select More / How do I? / Customize this menu.


 Wrap Text
     wEdCut()
     wrapText = ClipGet()
     wrap=AskLine("WinBatch Studio Text Wrapper","Enter a wrap value.","50")
        If wrap <= 20 Then wrap = 20
        offset = 1

     While offset + wrap <= StrLen( wrapText )

       
           If StrLen( wrapText ) < offset + wrap
                ;See if text line ends within wrap length.
                offset = offset + StrLen( wrapText )
                ;If so, reset the offset to the full file length.
           Else
                string = StrSub(wrapText,offset,wrap)
                ;Get the string defined by the wrap length.
                findCR = StrIndex(string,@CR,wrap,@BACKSCAN)
                ;Find a CR in the string or get a 0.
                findspace = StrIndex(string," ",0,@BACKSCAN)
                ;Find the last space in the string or get a 0.
             
                If findCR > 0
                ;If there is a CR,
                offset = offset + findCR
        
        ;set offset to the CR plus one character to
        ;allow for the LF in the CRLF often used in
        ;Windows text files. If the LF is not there,
        ;there is no effect of adding 1 to the offset.
         
                Else
                   If findspace > 0
                        string1 = StrSub( wrapText , 1 , offset + findspace -1 )
                        ;Insert a CRLF after the space (+1).
                        string2 =StrSub(wrapText,StrLen(string1),StrLen(wrapText)+1-StrLen(string1))
                        string2 = StrTrim(string2)
                        wrapText = StrCat( string1, @CRLF , string2)
                        drop(string1,string2)
                        offset = offset + findspace + 2
                        ; Reset the offset to the character after the Tab.
                   Else
                        offset = offset + wrap
                   EndIF
                EndIf
           EndIf
     EndWhile
     ClipPut(wrapText)
     Drop(wrapText)
     wEdPaste()



Article ID:   W14107
Filename:   Wrap lines to a specific length.txt
File Created: 2000:06:15:11:35:20
Last Updated: 2000:06:15:11:35:20