The RMVD() function extracts characters from a dynamic array up to the next delimiter character. It is closely related to REMOVE().
The RMVD() function is similar to the REMOVE() function but recognises only the field, value and subvalue marks as delimiters. Text marks and item marks are treated as part of the data. The function
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 point one character before the start of the string. Subsequent RMVD() operations advance the pointer by one character and then extract characters from the position of the remove pointer up to the next delimiter character or the end of the string. Because the remove pointer gives immediate access to the position at which the data extraction 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 removal. The delimiter character is not stored as part of the extracted substring. Values of var are
0 End of string
2 Field mark
3 Value mark
4 Subvalue 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 one character beyond the end of the string and further RMVD() operations would return a null string.
The remove pointer may be reset to the start of the string by assigning a new value to string. Where it is required to reset the remove pointer without changing the string, the SETREM statement can be used. Alternatively, applications frequently use a statement such as
S = S
which will assign S to itself thus resetting the remove pointer.
Note that the RMVD() function performs a type conversion on dyn.array if it is not already a string. Thus the program
S = 99
X = RMVD(S, 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.
BOOK.NO = RMVD(BOOK.LIST, DELIM)
PRINT "Book number is " : BOOK.NO
This program fragment extracts entries from the BOOK.LIST dynamic array and prints them. There is an assumption that BOOK.LIST is not a null string (in which case a single null BOOK.NO would be printed).
S = ""
FLD = RMVD(REC, DELIM)
S := FLD
IF DELIM = 2 OR DELIM = 0 THEN
S = ""
S := CHAR(256 - DELIM)
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
but may be much faster where REC is large and has a very large number of fields.