Re: UNSTRING performance issue
- From: "Richard" <riplin@xxxxxxxxxxxx>
- Date: 29 Nov 2005 10:36:11 -0800
> Given a delimited string of variable length (string-variable), suppose
> you are interested in the nth value in the string.
I usually find the CSV files or similar need something a little more
sophisticated than an UNSTRING as they sometimes have the quoted values
so I have routines that extract values (and sub-values) from a variety
of packed types so I would just do something like:
PERFORM Extract-field n TIMES
(process nth field)
However if you want quicker:
SUBTRACT 1 FROM n GIVING n-1
MOVE ZERO TO delimiter-count
INSPECT string-variable TALLYING delimiter-count
FOR ALL delimiter-variable
IF ( delimiter-count < n-1 )
(no n'th field)
ELSE
MOVE 1 TO string-pointer
PERFORM n-1 TIMES
PERFORM VARYING string-pointer BY 1
UNTIL string-variable(string-pointer:1) =
delimiter-variable
CONTINUE
END-PERFORM
ADD 1 TO string-pointer
END-PERFORM
UNSTRING string-variable
...
WITH POINTER string-pointer
END-IF
.
- References:
- UNSTRING performance issue
- From: Chris
- UNSTRING performance issue
- Prev by Date: Re: Making money from Java
- Next by Date: Re: Next generation COBOL?
- Previous by thread: Re: UNSTRING performance issue
- Next by thread: Re: UNSTRING performance issue
- Index(es):
Relevant Pages
|
|