omron — $DECODE string function

$DECODE string function output of the function. That is, this case returns all the leading break characters in the input string. Details This function is used to scan an input string and return the initial substring, as delimited by any of a group of break characters. After the substring is returned by the function, it is deleted from the input string. The string returned (and deleted) can either contain no break characters (mode 0), or nothing but break characters (mode 1).

That is, $DECODE can return (and delete) all the characters up to the first break character-usually some desired substring; or the function can return (and delete) all the leading break characters-which are usually discarded. By alternating the modes, groups of desired characters can be picked from the input string (see the first example below). The modes -2 and -3 copy all nonbreak characters up to the first break characters plus the first break character. Mode -2 is equivalent to the following instructions:

$s = $DECODE($i,$break,0) ;Extract up to 1st break character $s = $s+$MID($i,1,1) ;Add on 1st break character $i = $MID($i,2,127) ;Remove the break character The following instruction can perform these operations: $s = $DECODE($i,$break,-2) ;Extract through 1st break character Mode -3 is equivalent to mode -2 if a break character is present. However, if no break character is contained in the input string, mode -3 returns an empty string and leaves the input string unchanged. Examples The instructions below pick off consecutive numbers from the string $input, assuming that the numbers are separated by some combination of spaces and commas.

The first instruction within the DO structure sets the variable $temp to the substring from $input that contains the first number (and removes that substring from $input). The VAL function is used to convert the numeric string into its corresponding real value, which is assigned to the next element of the real array value. The $DECODE function is used a second time to extract the characters that separate the numbers (the characters found are ignored).

i = 0 ;Set array index DO $temp = $DECODE($string_var," ,",0) ;Pick off a number string value[i] = VAL($temp) ;Convert to real value $temp = $DECODE($string_var," ,",1) ;Discard spaces and eV+Language Reference Guide, v2.x, 18319-000 Rev A Page 150