Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Break a string into parts at an index, but not in the middle of a word

Status
Not open for further replies.

TomCo2

Programmer
Aug 3, 2007
1
IE
Hi,

I've been working on this program for a while now but I've hit a brick wall.

I need to spread a string across sereral variables at a specified index, but not when that index is in the middle of a word only when it is at a space. Its driving me nuts.

For example -
ONE HUNDRED AND FIFTY SIX THOUSAND EURO
with index = 20 points at 'T' in FIFTY. Count back to the closest space (16) and store everything up to that index in a variable.

Continue until index > length.


I was using something like this,

IF WS-LENGTH > WS-PARSE-INDEX
PERFORM VARYING WS-PARSE-INDEX FROM WS-PARSE-INDEX BY -1
UNTIL WS-PARSE-INDEX > WS-LENGTH

IF WS-CHEQUE-DATA(WS-PARSE-INDEX:1) = " "
UNSTRING WS-CHEQUE-DATA
INTO WW-CHEQUE-LINE(WS-LINE-INDEX)
WITH POINTER WS-PARSE-INDEX
END-UNSTRING

ADD 1 TO WS-PARSE-INDEX GIVING WS-PARSE-INDEX
ADD 1 TO WS-LINE-INDEX GIVING WS-LINE-INDEX
END-IF
END-PERFORM
END-IF.

But it doesnt work as intended.

This is really stressing me out at this stage.
 
(i will use a tilde as a special marker)

if ws-check-data (parse-index) = space
move "~" to ws-check-data (parse-index)
else perform findspace thru findspace-exit.
unstring ws-check-data delimited by "~" into new-data.


findspace.
perform until parse-index = 1
or ws-check-data (parse-index) = "~"
if ws-check-data (parse-index) = space
move "~" to ws-check-data (parse-index)
else set parse-index down by 1
end-perform.
findspace-exit. exit.
 
This code clearly never worked. Some suggestions...
Code:
IF WS-LENGTH > WS-PARSE-INDEX
  PERFORM VARYING WS-PARSE-INDEX FROM WS-PARSE-INDEX BY -1
            UNTIL WS-PARSE-INDEX[COLOR=white red] < 1 [/color]WS-LENGTH
               [COLOR=white red]OR WS-CHEQUE-DATA(WS-PARSE-INDEX:1) = SPACE[/color]
  END-PERFORM
  IF WS-PARSE-INDEX > 0
     [COLOR=white red]move[/color] WS-CHEQUE-DATA [COLOR=white red](1:WS-PARSE-INDEX) TO WW-CHEQUE-LINE(WS-LINE-INDEX)[/color]
  END-IF
END-IF.

These are merely suggestions. Your post indicates that there might be some sort of outer loop...

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top