Advertisement
ProgrammingChicken

wrap with comments

Aug 17th, 2018
3,933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DEF WRAP(S$,W)
  2.  VAR P 'space position
  3.  VAR O 'offset from beginning
  4.  DIM SPL$[0] 'lines array
  5.  IF LEN(S$)>W THEN 'if
  6.   REPEAT
  7.    IF MID$(S$,O+W,1)==" " THEN 'if there is a space at the beginning of the next line
  8.     P=W-1 'set position to the end of the line so the line stays whole
  9.    ELSE
  10.     FOR P=W-1 TO 0 STEP -1 'count backwards
  11.      IF MID$(S$,O+P,1)==" " THEN BREAK 'until space found
  12.     NEXT
  13.    ENDIF
  14.    PUSH SPL$,MID$(S$,O,P) 'push new line
  15.    INC O,P 'update offset
  16.   UNTIL O+W>LEN(S$) 'until there isn't even a full line left to use
  17.  ENDIF
  18.  PUSH SPL$,MID$(S$,O,LEN(S$)-O)'push last line
  19.  
  20.  FOR P=0 TO LEN(SPL$)-1
  21.   IF LEFT$(SPL$[P],1)==" " THEN SPL$[P]=RIGHT$(SPL$[P],LEN(SPL$[P])-1)
  22.  NEXT
  23.  
  24.  RETURN SPL$
  25. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement