Mid$
mid$ extracts a sub-string defined by the position and a number of characters out of a CLOB or a string.
Syntax
mid$(EXP_STRING,EXP_POS,EXP_NB)
EXP_STRINGis an expression returning a CLOB or string value.EXP_POSis an expression returning an integer value that is the position of the first character to be extracted.EXP_NBis an expression returning an integer value that defines the number of characters to be extracted.
Examples
# Extraction Of 3 characters from latin alphabet
Local Char ALPHABET(26), DEF(20), WXYZ(20)
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DEF=mid$(ALPHABET,4,3) : # DEF contains "DEF"
WXYZ=mid$(ALPHABET,23,10) : # DEF contains "WXYZ"
# inserts a space between every character in a string
MY_TITLE="WELCOME"
MY_TITLE=sigma(I=1,len(MY_TITRE),mid$(TITRE,I,1)+" ")
# Now MY_TITLE contains "W E L C O M E "
Description
The function mid$(EXP_STRING,EXP_POS,EXP_NB) extracts up to EXP_NB characters from the EXP_STRING string starting at the position EXP_POS.
The type of result is Char.
Comments
- If
EXP_POSis greater than the length of the string,mid$(EXP_STRING,EXP_POS,EXP_NB)returns the null string"". - If
EXP_NBis greater than the number of remaining characters, only the remaining characters will be extracted, and the length of the result is smaller thanEXP_NB. mid$(EXP_STRING,EXP_POS,EXP_NB)is equivalent toseg$(EXP_STRING,EXP_POS+EXP_NB-1).
Associated errors
| Error code | Description |
|---|---|
| 10 | The arguments type are not correct. |
| 50 | The position or the length is negative. |