Re: UNSTRING performance issue



> 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

.



Relevant Pages

  • Re: Text Box Question
    ... string. ... I think I'm right in saying that the Split array does not contain the ... > BTW you can use InStrand Mid$to extract 'lines' ... > Public Function StrExtStr$(StringIn$, Delimiter$, Nth%) ...
    (comp.lang.basic.visual.misc)
  • Re: General UNIX puzzle
    ... >standard UNIX tools, and am curious what answers people on the list might ... >1) Delete the Nth line from a text file? ... >2) Insert a specified line in a file after the Nth line, leaving the rest ... >3) Delete the first line containing a particular string? ...
    (freebsd-questions)
  • CSV values and retrieiving nth item
    ... I have a set of data in a cell that is comma delimited (more specifically - ... I want to select the nth item in each string. ... to an array via an array formula: ...
    (microsoft.public.excel.worksheet.functions)
  • General UNIX puzzle
    ... standard UNIX tools, and am curious what answers people on the list might ... Delete the Nth line from a text file? ... Insert a specified line in a file after the Nth line, leaving the rest ... Delete the first line containing a particular string? ...
    (freebsd-questions)
  • Re: General UNIX puzzle
    ... > standard UNIX tools, and am curious what answers people on the list might ... > 1) Delete the Nth line from a text file? ... > 2) Insert a specified line in a file after the Nth line, leaving the rest ... > 3) Delete the first line containing a particular string? ...
    (freebsd-questions)