Re: UNSTRING performance issue



In article <1133276339.806234.154820@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Chris <ctaliercio@xxxxxxxxx> wrote:
>Given a delimited string of variable length (string-variable), suppose
>you are interested in the nth value in the string.

Question of definition, please. Given the comma-delimited string:

VAL1,,VAL2

.... are you calling VAL2 the second or third value in the string?

>
>I'm currently using the following solution:
>
>MOVE "," TO delimiter-variable
>MOVE 1 TO string-pointer
>
>PERFORM n TIMES
>
> UNSTRING
> string-variable DELIMITED BY delimiter-variable
> INTO
> string-field
> WITH POINTER
> string-pointer
> ON OVERFLOW
> SET unstring-error TO TRUE
> EXIT PERFORM
> END-UNSTRING
>
>END-PERFORM

Wow... someone has done their own homework!

>
>
>Obviously, the larger the string, the slower the performance of this
>command.
>
>I'm wondering if there is a faster way to do this that I am as yet
>unaware of?

Depends on the compiler/platform, of course... but off the top of my
pointy little head, to find the data following the nth delimiter:

Perform Varying Sub1 from 1 by 1
Until All-Done
If Variable(Sub1:1) = delimiter
Add 1 to Delims-Found
Evaluate True
When Delims-Found = n
Perform Varying Sub2 from Sub1 by 1
Until Variable(Sub2:1) = delimiter
Or Sub2 > (Length of Variable)
Continue
End-Perform
Subtract 1 from Sub2
If Sub2 > 0
Move Variable(Sub1:Sub2) To Another-Field
Else
PERFORM B1520-EMPTY-FIELD-RITUAL THRU B1520-EFR-EX
End-Evaluate
End-If
End-Perform

.... or something like that, the errors in my extemporaneous coding should
be obvious.

DD
.



Relevant Pages

  • Re: Programmers unpaid overtime.
    ... tokenizing a string correctly. ... ability to specify a set of delimiter tokens, ... >> postmodern attack on language itself, ... An the scientists, in turn, think a lot of that artistic talk about ...
    (comp.programming)
  • Re: Surprise in StrConv using vbProperCase
    ... > Your code will capitalize the first letter of a string. ... Use Split(string into array of words using blank as delimiter); ...
    (microsoft.public.access.modulesdaovba)
  • Re: VB vs C#
    ... Dim delimiter As String ... Dim testname As String ...
    (microsoft.public.dotnet.general)
  • Re: Clarification
    ... With your strings in column A, select the data and then pick Text to Columns delimited with space and comma as the delimiter. ... And a bit of advice from one who's often been there and done that: forget about the concatenation - leave the data separated by columns. ... With your string in column A, Text to Columns fixed width could give you ... >> re-assemble them using concatenation and copying down ...
    (microsoft.public.excel.misc)
  • Re: INSERT Query problem with Quotes & Apostrophes
    ... Position of match string, ... Dim intI As Integer, intLenC As Integer, intLenM As Integer ... An array of strings and an optional delimiter ... Dim strWork As String ...
    (microsoft.public.access.modulesdaovba)