Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DEF WRAP(S$,W)
- VAR P 'space position
- VAR O 'offset from beginning
- DIM SPL$[0] 'lines array
- IF LEN(S$)>W THEN 'if
- REPEAT
- IF MID$(S$,O+W,1)==" " THEN 'if there is a space at the beginning of the next line
- P=W-1 'set position to the end of the line so the line stays whole
- ELSE
- FOR P=W-1 TO 0 STEP -1 'count backwards
- IF MID$(S$,O+P,1)==" " THEN BREAK 'until space found
- NEXT
- ENDIF
- PUSH SPL$,MID$(S$,O,P) 'push new line
- INC O,P 'update offset
- UNTIL O+W>LEN(S$) 'until there isn't even a full line left to use
- ENDIF
- PUSH SPL$,MID$(S$,O,LEN(S$)-O)'push last line
- FOR P=0 TO LEN(SPL$)-1
- IF LEFT$(SPL$[P],1)==" " THEN SPL$[P]=RIGHT$(SPL$[P],LEN(SPL$[P])-1)
- NEXT
- RETURN SPL$
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement