MID$ |
mid$ is used to extract a sub-string starting from a particular position and over a certain length in a character string.
mid$( string, rank, nb_char )
|
Element |
Description |
Restrictions |
|
string |
Alphanumeric expression |
None. |
|
rank |
Numerical integer expression for the position extraction begins. |
position >= 0 |
|
nb_char |
Numerical integer expression for the length of string to be extracted. |
nb_char >= 0 |
# Extraction of 3 letters of the alphabet
from the 4th letter;
# this programme displays "DEF"
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Infbox mid$ (ALPHABET, 4, 3)
# Display of a title separating the
characters with a space
Infbox sigma(I = 1,len(TITRE), mid$(TITRE, I,
1)+" ")
The function mid$(string,rank,nb_char) extracts nb_char maximum characters from the string, starting from the position rank.
The result is a Char type.
If rank is greater than the length of the string, mid$ (string, rank, nb_char) returns the empty string "". If the length of string is insufficient (that is, if rank+nb_char-1 > len(string) ), the number of characters extracted will be fewer than nb_char. An error is never generated from one of these two conditions.
|
Error |
Description |
|
ERMODE (10) |
The arguments are not of the corresponding type. |
|
ERDOM (50) |
Position or length of truncation negative. |
|
|