LEFT$

Contents


left$ is used to extract a sub-string from the leftmost end (from the start) of a character string.

 

Syntax

   left$( string, nb_char )

 

Parameters

Element

Description

Restrictions

string

Alphanumeric expression.

None.

nb_char

Numerical integer expression for the length of string to be extracted.

nb_char >= 0

 

Examples

   # Extraction of the first 5 letters of the alphabet.
   # This programme displays "ABCDE"
    ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Infbox left$(ALPHABET, 5)
   # Calculation of the length of a character string CHAINE;
   # (it is simpler to use the len function)
    I = 0
    While left$(CHAINE,I) <> CHAINE  :# as long as equality is not
           I += 1                    :# found, increment I
    Wend
    Infbox "The length of the string "-CHAINE-" is" num$(I)
    # When CHAINE is "ABCDEFG", the programme displays:
    # The length of the string "ABCDEFG" is 7
    # To display a string, cutting it to 32 characters.
    # This works even if len(CHAINE) < 32
    Infbox left$(CHAINE, 32)

 

Description and comments

The function left$(string, nb_char) extracts the first nb_char characters from the string.

The result is a Char type.

 

Comments

If nb_char is 0, left$(string, nb_char) is equal to the empty string "".

If nb_char is greater than the length of the string, left$(string, nb_char) returns the whole string, without generating an error.

 

Associated errors

Error

Description

ERMODE (10)

string is not a Char type or nb_char is not numerical.

ERDOM (50)

nb_char < 0

 

Associated key words

MID$ - RIGHT$ - SEG$ - LEN


CONTENTS


Copyright © Sage 1999 - 2007