Scripting > 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(Val, Start [, Length])
Parameters
Val
Type: Type: None
Text value, categorical value, or array to operate on.
Start
Type: Type: Long
Position in Val of the first character, category, or element wanted (counting from 0). If Start is greater than the number of items in Val, no items are returned. If Start is less than 0, items are returned from the start of Val.
Length
Type: Type: Long
Optional. Number of characters, categories, or elements to return. If Length is omitted, or if there are fewer than Lengthcharacters (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 Val.
Remarks
For type Text, the return value is of type Text, and contains Length characters from the position Start in Val. For type Categorical, the value is of type Categorical, and contains Length categories from the position Start in Val. 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 Val. For any other type, an error occurs.
When Val 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. See Split for more information.
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