INSTR

Contents


instr is used to find a given sub-string in a character string, from a character of a given position in the string.

 

Syntax

   instr( rank, string, sub_string )

 

Parameters

Element

Description

Restrictions

rank

Integer type expression giving the position corresponding to the 1st character in the string from which the sub-string search begins.

position > 0

string

Char type expression representing the string in which the search is carried out.

None.

sub_string

Char type expression representing the sub-string searched for.

None.

 

Examples

   # Search for an 'ABC' character string in a given string;
   # with the following parameters this programme displays 3
    Infbox num$(instr(1,"ABC is in an alphabetical list",'ABC'))

   # Count the number of MOT words in a TEXTE text
   # and place the result in the variable CPT
    CPT = -1 : I = 0
    Repeat I =
instr(I+1, TEXTE, MOT) : CPT += 1 : Until I = 0

 

Description and comments

instr looks for sub_string in string from the position and gives the position (in number of characters) of the first character for the sub-string searched for. If the sub-string is not present, or if position <= 0, instr returns 0.

 

Associated errors

Error

Description

ERMODE (10)

- position is not a numerical type.
- string or sub-string is not a Char type.

ERDOM (50)

position < 0

 

Associated key words

LEFT$ - RIGHT$ - STRING$ - SPACE$ - SEG$ - MID$ - VIREBLC


CONTENTS


Copyright © Sage 1999 - 2007