Breaking a line on a word

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Breaking a line on a word

  • Creator
    Topic
  • #51053
    Michael Hertel
    Participant

    Mission:

    Format a blob of text to many lines that do not exceed 75 chars in length and doesn’t split up a word.

    Either I was dreaming, or I thought there was a command that used a switch like -word to parse on whitespace.

    I can’t find the command though.

Viewing 4 reply threads
  • Author
    Replies
    • #68604
      Chris Williams
      Participant

      I have some tcl code that does what you want. EM me if you’d like a copy.

    • #68605
      David Barr
      Participant

      You’re probably thinking of the unix “fold” command.

    • #68606
      Tom Rioux
      Participant

      Michael,

      If you type in the following command:

      string wordstart $msg 75

      It will return the index at the start of the word before the 75th character (including spaces and punctuation).  If you subtract 1 from the index number that is returned, that will be the last whitespace before the 75th character.   Remember that the count starts at 0 so if it returns a “72” then the whitespace will be at index 71.  From there you can use iteration and a string range command to do the manipulating to bust it up into lines.   The 75 can even be set as counter that is incremented (i.e 75, 150 etc)

      Hope this helps…

      Tom Rioux

    • #68607
      Michael Hertel
      Participant

      Perfect. Thanks Tom!

      Chris, thanks too!

    • #68608
      Dennis Pfeifer
      Participant

      ;##how about text util .. .

      package require textutil

      ;## assume ‘text’ is in $text

      set textList [split [textutil::adjust $text -length 75] “n”]

      ;## textList now contains a list

      ;## with each element containing one line of text.

      ;## Dennis..

Viewing 4 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,116
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10