Mid Command
Obsolete
This command is replaced by the Mid function.
Purpose
To move a specified number of characters, starting at a specified position, from a variable to another variable.
Syntax
mid value to variable [length [start_position]]
start_position may be specified only if length is specified.
What It Does
Mid copies length characters from value, starting at start_position, and puts them in variable.
mid "NEW HAMPSHIRE" to part 3 5
The above command puts "HAM" (the three characters starting at Position 5) in part. The value 3 is moved to the predefined variable strlen, and 5 to the predefined variable strmark.
Either of the numeric arguments may be variables.
string phone_number area_code
number start
pos "(" in phone_number to start
mid phone_number to area_code 3 (start + 1)
In this example, the position of the first open parenthesis is determined in the value of phone_number and moved to the number variable start. Then the 3 characters following the open parenthesis (start + 1) are moved to area_code.
If start_position is omitted, the value of the predefined variable strmark is used for the function. If both start_position and length are omitted, the value of the predefined variable strlen will be used for length, and strmark for start_position. strmark is set by the previous insert, left, pad, pos, replace, or sysdate command. strlen is set by the previous pos, right, or sysdate command.
Notes
- If
lengthis less than 1,midwill emptyvariable. - If
lengthis greater than the length ofvalue,midwill return the rightmost portion ofvalue, starting atstart_position. - If
start_positionis less than 1,midwill emptyvariable. - If
start_positionis greater than the length ofvalue,midwill emptyvariable. - Although
midcan be used on Date, Integer, and Number type variables, it is typically used on String type variables. valueandvariablemay be the same variable. Used this way,midsimply truncatesvalueto the left ofstart_positionand to the right ofstart_positionpluslength:
mid account_number to account_number 3 8
In this example, all characters before the third (counted from the left) and after the eleventh are removed from the value of variable account_number.