Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PrintW - print a long string, breaking it at the last space or hyphen before col. 79
#8
Not very 'fisticated, but this works:

Code: (Select All)
text$ = "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal."
text$ = text$ + " " '                                                                              add space at end to catch remnant of text

LineStart = 1 '                                                                                    set linelength to be 40
Print String$(40, "-") '                                                                           reference 40 char string
LineEnd = LineStart + 39 '                                                                         LineEnd is 40
FindSpace:
Ch$ = Mid$(text$, LineEnd + 1, 1)
If Ch$ <> " " Then '                                                                               Ch$ is character after LineEnd
    LineEnd = LineEnd - 1 '                                                                        if it's NOT a space, move LineEnd left until it IS
    GoTo FindSpace
End If
Print Mid$(text$, LineStart, LineEnd - LineStart + 1) '                                                print line from linestart to lineend
LineStart = LineEnd + 2
If Mid$(text$, LineStart + 1, 1) = " " Then '                                                       if char after end is a space (it's not)
    LineStart = LineStart + 1 '                                                                     step past it for new LineStart position
End If
LineEnd = LineEnd + 40
If LineStart >= Len(text$) Then Sleep
GoTo FindSpace '                                                                                    go again if not at end of text
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply


Messages In This Thread
RE: PrintW - print a long string, breaking it at the last space or hyphen before col. 79 - by PhilOfPerth - 04-15-2024, 06:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  STRING$ empowered with StringPatternFilling TempodiBasic 6 1,244 05-09-2025, 06:00 PM
Last Post: TempodiBasic
  Split String to Array Using Strtok (Attempt #2) SpriggsySpriggs 0 548 12-17-2024, 06:37 PM
Last Post: SpriggsySpriggs
  print file bplus 11 2,178 04-27-2024, 03:37 AM
Last Post: eoredson
  Fonts from String Patterns bplus 15 3,765 08-30-2023, 03:01 PM
Last Post: grymmjack
Music Fake space music mnrvovrfc 2 1,116 06-27-2023, 05:10 PM
Last Post: Petr

Forum Jump:


Users browsing this thread: 1 Guest(s)