Developer Documentation Library > UNICOM Intelligence Function Library > Text, categorical, and array functions > Mid
 
Mid
Returns a string containing a number of characters from a position in a string, a category list containing a number of categories from a position in a category list, or an array containing a number of elements from a position in an array.
Syntax
Mid(<value>, <start> [, <length>])
Parameters
<value>
Type: Type: None
Text value, categorical value, or array to operate on.
<start>
Type: Type: Long
Position in <value> of the first character, category, or element wanted (counting from 0). If Start is greater than the number of items in <value>, no items are returned. If Start is less than 0, items are returned from the start of <value>.
<length>
Type: Type: Long
(Optional.) Number of characters, categories, or elements to return. If <length> is omitted, or if there are fewer than <length> characters (including the <start> character), all characters from <start> to the end of the string are returned. If <start> + <length> is < 1, no items are returned.
(return)
Type: Type: None
The required characters, categories, or elements from <value>.
Notes
For type Text, the return value is of type Text, and contains Length characters from the position <start> in <value>. For type Categorical, the value is of type Categorical, and contains Length categories from the position <start> in <value>. For an array (which can contain values of any type), the return value is an array, and contains <length> elements from the position Start in <value>. For any other type, an error occurs.
When <value> is NULL, the return value is NULL.
Examples
Function call
Val
Start
Length
Result
Notes
Mid(Val, Start, Length)
24 St John's Road, Barnes
10
15
's Road, Barnes
The return value is the 15 characters following the 10th character in the supplied string.
Mid(Val, Start, Length)
{4,2,9}
2
1
{9}
The return value is the category following the second category in the supplied category list.
Mid(Val, Start, Length)
{4,2,9}
6
3
{}
The return value is an empty category list, because Start is greater than the number of categories in the supplied category list.
Mid(Val, Start, Length)
{4,2,9}
0
2
{4,2}
The return value is the first two categories in the supplied category list.
Mid(Val, Start, Length)
{4,2,9}
0
 
{4,2,9}
The return value is all characters from Start to the end of the string.
Mid(Val, Start, Length)
Split("The quick brown fox")
1
2
{quick,brown}
The return value is the two elements following the first element in the supplied array. For more information, see Split.
The following example returns characters 8-17 from the address text variable:
address.Mid(7, 10)
The following example returns the fourth category from the list of categories stored in the remember multiple response variable:
remember.Mid(3, 1)
For respondents who chose less than four categories, this returns an empty category list ({}).
For an example of using Mid in combination with UCase and Trim, see UCase. For ideas for using Mid in SQL queries, see I want to use the Data Model to access data, but I am used to SPSS-style data. Can you give me an overview?.
See also
Find
Text, categorical, and array functions