Advertisement
jargon

KSDK :: String Support :: Word Wrap

Mar 24th, 2024
1,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
FreeBasic 1.57 KB | Gaming | 0 0
  1. sub wordWalk(text as string=EMPTY, wordSep as string = SP, lineSep as string = CRLF, ledger(any) as string,ww as longint)
  2.    
  3.     dim as longint scrw=0, scrh=0, scrdepth=0, scrbpp=0, scrpitch=0, scrrate=0
  4.     dim as string scrdriver=EMPTY
  5.  
  6.     Screeninfo ( scrw, scrh, scrdepth, scrbpp, scrpitch, scrrate, scrdriver )
  7.  
  8.     dim as longint owordSep=0, olineSep=0
  9.  
  10.     if ww=0 then
  11.         ww=scrw/8
  12.     end if
  13.  
  14.     dim as string buffer=EMPTY,reserve=EMPTY
  15.     dim as longint index=0,offset=0
  16.    
  17.     erase ledger
  18.    
  19.     reserve=text
  20.    
  21.     do while len(reserve) GTR 0
  22.        
  23.         owordSep=instr(reserve,wordSep)
  24.         olineSep=instr(reserve,lineSep)
  25.        
  26.         if (owordSep GTR 0) or (olineSep GTR 0) then
  27.             if (owordSep LSS olineSep) and (owordSep GTR 0) then
  28.                
  29.                 if len(ledger(ubound(ledger,1)) & mid(reserve,1,owordSep-1)) GTR ww then
  30.                     redim preserve ledger(lbound(ledger,1) to ubound(ledger,1)+1)
  31.                 end if
  32.                
  33.                 ledger(ubound(ledger,1)) &= mid(reserve,1,owordSep-1)
  34.                 reserve = mid(reserve,owordSep+len(wordSep))
  35.                
  36.             elseif (olineSep LSS owordSep) and (olineSep GTR 0)  then
  37.                
  38.                 ledger(ubound(ledger,1)) &= mid(reserve,1,olineSep-1)
  39.                
  40.                 reserve = mid(reserve,olineSep+len(lineSep))
  41.                 redim preserve ledger(lbound(ledger,1) to ubound(ledger,1)+1)
  42.                
  43.             end if
  44.         end if
  45.                
  46.     loop
  47.    
  48.     dim as longint fm=0
  49.     fm=freefile
  50.     if open("ledger.txt" for output as #fm) NEQ 0 then
  51.         close #fm
  52.         return
  53.     end if
  54.     print #fm,lbound(ledger,1),ubound(ledger,1)
  55.     for index=lbound(ledger,1) to ubound(ledger,1) step 1
  56.         print #fm,index,ledger(index)
  57.     next index
  58.     close #fm
  59.    
  60.     return
  61.    
  62. end sub
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement