Mid$
mid$
extracts a sub-string defined by the position and a number of characters out of a CLOB or a string.
mid$(EXP_STRING,EXP_POS,EXP_NB)
EXP_STRING
is an expression returning a CLOB or string value.EXP_POS
is an expression returning an integer value that is the position of the first character to be extracted.EXP_NB
is an expression returning an integer value that defines the number of characters to be extracted. # Extraction Of 3 characters from latin alphabetLocal 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 stringMY_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 "
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.
EXP_POS
is greater than the length of the string, mid$(EXP_STRING,EXP_POS,EXP_NB)
returns the null string ""
.EXP_NB
is greater than the number of remaining characters, only the remaining characters will be extracted, and the length of the result is smaller than EXP_NB
.mid$(EXP_STRING,EXP_POS,EXP_NB)
is equivalent to seg$(EXP_STRING,EXP_POS+EXP_NB-1)
.Error code | Description |
---|---|
10 | The arguments type are not correct. |
50 | The position or the length is negative. |