REMOVE, REMOVE() |
![]() ![]() ![]() |
The REMOVE statement and REMOVE() function extract characters from a dynamic array up to the next mark character.
Format
REMOVE string FROM dyn.array SETTING var REMOVE(dyn.array, var)
where
The statement
S = REMOVE(X, Y)
is equivalent to
REMOVE S FROM X SETTING Y
The REMOVE operation associates a remove pointer with the dyn.array from which data is extracted. Whenever a string is assigned to a variable the remove pointer is set to the start of the string. Subsequent REMOVE operations extract characters from the position of the remove pointer up to the next mark character or the end of the string. Because the remove pointer gives immediate access to the position at which the REMOVE should commence, this operation can be much faster than field, value or subvalue extraction.
The value returned in var indicates the delimiter that terminated the REMOVE. The delimiter character is not stored as part of the extracted substring. Values of var are
0 End of string 1 Item mark 2 Field mark 3 Value mark 4 Subvalue mark 5 Text mark
The mark character itself can be reconstructed as CHAR(256 - var) for a non-zero value of var.
Once the end of the dyn.array has been reached, the remove pointer remains positioned at the end of the string and further REMOVE operations would return a null string.
The remove pointer may be reset to the start of the string by assigning a new value to dyn.array. Where it is required to reset the remove pointer without changing the string, a statement such as
S = S
will assign S to itself thus resetting the remove pointer.
There is a limit to the number of remove pointers that can be active at one time. A remove pointer that is set to the start of the string is not considered to be active. It is useful to reset remove pointers when they are no longer required if the variable will not be reassigned. Remove pointers associated with a program or subroutine are reset automatically when the program terminates and its variables are released.
Note that the REMOVE operation performs a type conversion on dyn.arrray if it is not already a string. Thus the program
S = 99 REMOVE X FROM S SETTING DELIM
would convert S to be a string "99". Although this is unlikely to have any undesirable effects, it is a side effect to be aware of.
Examples
LOOP REMOVE BOOK.NO FROM BOOK.LIST SETTING DELIM PRINT "Book number is " : BOOK.NO WHILE DELIM REPEAT
This program fragment extracts entries from the BOOK.LIST dynamic array and prints then. There is an assumption that BOOK.LIST is not a null string (in which case a single null BOOK.NO would be printed).
S = "" LOOP REMOVE FLD FROM REC SETTING DELIM S := FLD IF DELIM = 2 OR DELIM = 0 THEN PRINT S S = "" END ELSE S := CHAR(256 - DELIM) END WHILE DELIM REPEAT
This program prints fields from REC. Note the use of the ELSE clause to append the delimiter that terminated the substring if it was not a field mark or the end of the string.
This is equivalent to
N = DCOUNT(REC, @FM) FOR I = 1 TO N PRINT REC<I> NEXT I
but may be much faster where REC is large and has a very large number of fields.
See also: |