MID$

Contents


mid$ is used to extract a sub-string starting from a particular position and over a certain length in a character string.

 

Syntax

   mid$( string, rank, nb_char )

 

Parameters

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

 

Examples

   # 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)+" ")

 

Description and comments

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.

 

Comments

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.

 

Associated errors

Error

Description

ERMODE (10)

The arguments are not of the corresponding type.

ERDOM (50)

Position or length of truncation negative.

 

Associated key words

RIGHT$ - LEFT$ - SEG$ - LEN


CONTENTS]


Copyright © Sage 1999 - 2007