_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 "press any for printWrap demo... "
PRINT "Here is printWrap at row = 12, col = 1, wrap length is 80:" printWrap test$, 80, 12, 1
PRINT "Here is printWrap at row = 9, col = 20, wrap length is 40:" printWrap test$, 40, 9, 20
PRINT "Here is printWrap at row = 5, col = 30, wrap length is 20:" printWrap test$, 20, 5, 30
'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
p = maxLen + 1
p = p - 1
wrap$
= MID$(s$
, 1, maxLen
): tail$
= MID$(s$
, maxLen
+ 1) wrap$
= MID$(s$
, 1, p
- 1): tail$
= MID$(s$
, p
+ 1) wrap$ = s$: tail$ = ""
'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
LOCATE rowOffset
+ i
, colOffset:
PRINT wrap$
(ss$
, maxLen
, st$
) ss$ = st$
i = i + 1