Skip to content

Mid Command

Obsolete

This command is replaced by the Mid function.

See Also

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 length is less than 1, mid will empty variable.
  • If length is greater than the length of value, mid will return the rightmost portion of value, starting at start_position.
  • If start_position is less than 1, mid will empty variable.
  • If start_position is greater than the length of value, mid will empty variable.
  • Although mid can be used on Date, Integer, and Number type variables, it is typically used on String type variables.
  • value and variable may be the same variable. Used this way, mid simply truncates value to the left of start_position and to the right of start_position plus length:
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.