title: Algorithm to exteact words from an string
body: <p>I’m woking with TELON/COBOL atm, i need an algorithm to extract words from a strings. 
  Tried searching but couldn’t find anything similar. </p>
  
  <p>Anyway the algorithm needs to extract the words, and ignore spaces; here is what i have so far (ive put in comments for people who aren’t familiar with e syntax)</p>
  
  <p>WS-STRING is the input string</p>
  
  <p>WS-WORD-LEN is the length of the word to be extracted</p>
  
  <p>WS-LST-WORD-P is the starting position of the current word to be extracted (within the sting)</p>
  
  <p>WS-SUB1 is the loop index</p>
  
  <pre><code>PERFORM TEST BEFORE                                      
  VARYING WS-SUB1 FROM 1 BY 1                              
    UNTIL WS-SUB1 &gt; WS-STRING-LEN //loop for each char in the string, add 1 to WS-SUB1 in each itiaration                         
      EVALUATE TRUE                                        
         WHEN WS-STRING(WS-SUB1:1) = SPACES  //if the current char is a space              
              MOVE WS-SUB1              TO WS-SUB1-FRD     
              ADD  1                    TO WS-SUB1-FRD     
              IF WS-STRING(WS-SUB1-FRD:1) = SPACES  //Checks to see if the next char is a space       
                  ADD  1                TO WS-LST-WORD-P   
              ELSE                                         
                  MOVE WS-STRING(WS-LST-WORD-P:WS-WORD-LEN) //Substing "WS-WORD-LEN" many char from "WS-STRING" starting at "WS-LST-WORD-P" into "WS-WORD-OUT" 
                                        TO WS-WORD-OUT     
                  ADD  1                TO WS-COUNT(2)     
                  PERFORM Z-400-OUTPUT-WORD  //This outputs "WS-WORD-OUT" to a file.              
                  MOVE WS-SUB1          TO WS-LST-WORD-P   
                  MOVE 1                TO WS-WORD-LEN   
              END-IF                                     
         WHEN OTHER                                      
              ADD  1                    TO WS-WORD-LEN   
      END-EVALUATE                                       
  END-PERFORM                                            
  MOVE 1                               TO WS-LST-WORD-P  
  </code></pre>
  
  <p>This algorithm sort of works, but some of the output is spliced at the beginning/end. 
  so any ideas on whats wrong here or suggest something better?</p>