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
#2
yes that could be handy but even more so if you can set the width ie just change 79 to something input from function call. then, you are a short step away from creating a word box of text at row, column and cutting up a long string into it.

this was maybe before -InStrRev/
Code: (Select All)
_Title "wrap$ test" 'b+ 2019-12-28  a simple way

'now test in graphics screen
'SCREEN _NEWIMAGE(640, 600, 32) 'now test in graphics screen

Print "Here is our test string:"
test$ = "12345678901234567890123456789012345678901234567890123456789012345678901234567890     Here is a super long string to test with the wrap$ Function that splits a string at first space found before the maxLen limit to keep the strings at or under the maxLen length."
Print test$
Print
Print "press any for printWrap demo... "
Sleep
Cls

Print "Here is printWrap at row = 12, col = 1, wrap length is 80:"
printWrap test$, 80, 12, 1
Locate 25, 20: Print "press any for another demo... ";
Sleep
Cls

Print "Here is printWrap at row = 9, col = 20, wrap length is 40:"
printWrap test$, 40, 9, 20
Locate 25, 20: Print "press any for another demo... ";
Sleep
Cls

Print "Here is printWrap at row = 5, col = 30, wrap length is 20:"
printWrap test$, 20, 5, 30
Locate 24, 20: Print "end of demos... ";


'This function returns the first segment of string less than or equal to maxLen AND
'the remainder of the string (if any) is returned in tail$ to be used by wrap$ again
Function wrap$ (s$, maxLen, tail$)
    If Len(s$) > maxLen Then
        p = maxLen + 1
        While Mid$(s$, p, 1) <> " " And p > 1
            p = p - 1
        Wend
        If p = 1 Then
            wrap$ = Mid$(s$, 1, maxLen): tail$ = Mid$(s$, maxLen + 1)
        Else
            wrap$ = Mid$(s$, 1, p - 1): tail$ = Mid$(s$, p + 1)
        End If
    Else
        wrap$ = s$: tail$ = ""
    End If
End Function

'this sub uses the wrap$ function to print out a string with row and column offsets
Sub printWrap (s$, maxLen, rowOffset, colOffset)
    ss$ = s$ 'work with copy
    Do
        Locate rowOffset + i, colOffset: Print wrap$(ss$, maxLen, st$)
        ss$ = st$
        i = i + 1
    Loop Until Len(ss$) = 0
End Sub
b = b + ...
Reply


Messages In This Thread
RE: PrintW - print a long string, breaking it at the last space or hyphen before col. 79 - by bplus - 04-14-2024, 06:02 PM



Users browsing this thread: 1 Guest(s)